[英]entity framework mapping fluent api seperate entity map
I'm trying to separate my entity map but when do that no changes applied on DB. 我正在尝试分离我的实体地图但是什么时候没有对数据库应用更改。 Why? 为什么?
Following is my code : 以下是我的代码:
//class for example
class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
this.ToTable("User");
this.HasKey<int>(p => p.Id);
this.Property(u => u.UserPin).IsRequired().HasMaxLength(2000);
}
}
//my project context
public class ProjectDbContext : DbContext
{
public ProjectDbContext()
: base("name=DefaultConnectionString")
{
}
public DbSet<Project> Projects { get; set; }
public DbSet<Image> Images { get; set; }
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//inject my user map rules
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new UserMap());
}
}
How to inject my map configuration to apply? 如何注入我的地图配置申请?
You can try as shown below.You have missed the public
key word :D 您可以尝试如下所示。您错过了public
关键词:D
public class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
this.ToTable("User");
this.HasKey<int>(p => p.Id);
this.Property(u => u.UserPin).IsRequired().HasMaxLength(2000);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.