labdb/Models/Country.cs
2022-11-19 22:25:07 +01:00

33 lines
1,016 B
C#

using System.ComponentModel;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace labdb.Models;
public record CountryId : EntityIdBase<CountryId>;
public class Country : EntityBase<CountryId>
{
public string Name { get; init; } = null!;
public string EnglishName { get; init; } = null!;
public string Code { get; init; } = null!;
public List<Lab> Labs { get; set; } = new();
}
public class CountryConfiguration : EntityBaseConfiguration<Country, CountryId>
{
public override void Configure(EntityTypeBuilder<Country> builder)
{
base.Configure(builder);
builder.HasIndex(x => x.Name, "name").IsUnique();
builder.HasIndex(x => x.Name, "name_trgm").HasMethod("gin").HasOperators("gin_trgm_ops");
builder.HasData(
new Country { Name = "Deutschland", EnglishName = "Germany", Code = "DE" },
new Country { Name = "TEST", EnglishName = "TEST COUNTRY", Code = "TEST" }
);
}
}