EF 7映射EntityTypeConfiguration [英] EF 7 Mapping EntityTypeConfiguration
本文介绍了EF 7映射EntityTypeConfiguration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在EF6我们通常能够用这种方式来配置实体
In EF6 we usually able to use this way to configure the Entity
public class 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);
}
}
我们如何能够EF 7,做自当I类继承EntityTypeConfiguration是无法找到类。
How we can do in EF 7, since when the class I Inherit EntityTypeConfiguration that unable to find the class.
我下载从GitHub上EF 7原始的源代码,我找不到它。
有人能帮助这一点。
I download the EF 7 raw source code from the github, I can't find it. Can someone help on this.
推荐答案
在EF7,可以覆盖OnModelCreating对你实施的DbContext类。
In EF7, you override OnModelCreating on the DbContext class you're implementing.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Account>()
.ForRelational(builder => builder.Table("Account"))
.Property(value => value.Username).MaxLength(50)
.Property(value => value.Email).MaxLength(255)
.Property(value => value.Name).MaxLength(255);
}
这篇关于EF 7映射EntityTypeConfiguration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文