EF Core 2.0和EF6(Entity Framework 6)中配置实体映射关系
时间:2022-08-22
1、EF6中通过EntityTypeConfiguration配置实体映射关系代码
public >AccountMap : EntityTypeConfiguration<Account> { public AccountMap() { ToTable("Account"); HasKey(a => a.Id); Property(a => a.Username).HasMaxLength(50); Property(a => a.Email).HasMaxLength(255); Property(a => a.Name).HasMaxLength(255); } }
2、EF Core 2.0中配置实体映射关系代码
>CustomerConfiguration : IEntityTypeConfiguration<Customer> { public void Conp(EntityTypeBuilder<Customer> builder) { builder.HasKey(c => c.AlternateKey); builder.Property(c => c.Name).HasMaxLength(200); } } public >BloggingContext : DbContext { protected override void OnModelCreating(ModelBuilder modelBuilder) { builder.ApplyConfiguration(new CustomerConfiguration()); } }
EF Core 2.0文档:https://docs.microsoft.com/en-us/ef/core/what-is-new/
特别声明:本站部分内容收集于互联网是出于更直观传递信息的目的。该内容版权归原作者所有,并不代表本站赞同其观点和对其真实性负责。如该内容涉及任何第三方合法权利,请及时与824310991@qq.com联系,我们会及时反馈并处理完毕。