Skip to content
LiZhengHao edited this page Jul 22, 2024 · 3 revisions

EfCore

使用雪花id作为主键

public class Model:EfEntity<long>
{

}

引入需要使用的雪花算法库,然后自己手动设置id值

模型实体配置

public class CustomModel:EfEntity<int>,IEntityTypeConfiguration<CustomModel>
{
   public string Category {get;set;}

   public List<OtherModel> OtherModels{get;set;}

   public void Configure(EntityTypeBuilder<AccuracyParameter> builder)
   {
       // 设置最大长度
        builder.Property(it=>it.Category)
            .HasMaxLength(-1);
      // 多对多(不配置也可以,默认映射)
      builder.HasMany<OtherModel>(x => x.OtherModels)
            .WithMany(x => x.CustomModels);
   }
}
Clone this wiki locally