【问题标题】:CodeFirst mapping relationship between entitiesCodeFirst 实体之间的映射关系
【发布时间】:2014-11-18 12:22:12
【问题描述】:

拥有这两个实体:

public partial class Title
{
    public int Id { get; set; }
    public string Description { get; set; }
}

public partial class Person
{
    public int Id { get; set; }
    public string Description { get; set; }
    public virtual Title Title { get; set; }
}

我如何映射关系以便在 Person 中需要 Title?

【问题讨论】:

    标签: c# entity-framework ef-code-first


    【解决方案1】:

    您可以使用Fluent API

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Person>()
                    .HasRequired(a => a.Title);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 2018-10-21
      • 2019-03-27
      • 2011-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多