35 lines
1 KiB
C#
35 lines
1 KiB
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<City> Cities { get; set; } = new();
|
|
|
|
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" }
|
|
);
|
|
}
|
|
} |