java EF6,EF Core 2.0和EF6(Entity Framework 6)中配置实体映射关系
1、EF6中通過EntityTypeConfiguration配置實(shí)體映射關(guān)系代碼
public class AccountMap : EntityTypeConfiguration
{
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中配置實(shí)體映射關(guān)系代碼
class CustomerConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(c => c.AlternateKey);
builder.Property(c => c.Name).HasMaxLength(200);
}
}
public class BloggingContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
builder.ApplyConfiguration(new CustomerConfiguration());
}
}
總結(jié)
以上是生活随笔為你收集整理的java EF6,EF Core 2.0和EF6(Entity Framework 6)中配置实体映射关系的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php两段音频合成一个,两段音乐合并 如
- 下一篇: oracle分页数据,在Oracle中得