簡體   English   中英

實體框架映射流暢的api單獨的實體地圖

[英]entity framework mapping fluent api seperate entity map

我正在嘗試分離我的實體地圖但是什么時候沒有對數據庫應用更改。 為什么?

以下是我的代碼:

//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());

    }
}

如何注入我的地圖配置申請?

您可以嘗試如下所示。您錯過了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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM