【问题标题】:EntityFramework. Fluent Api. Invert mapping实体框架。流利的 API。逆映射
【发布时间】:2016-08-11 09:49:20
【问题描述】:

我有以下课程:

class Parent
{
    public int ID;
    public Child Child1;
    public Child Child2;
}

class Child
{
    public int ID;
    public string Data;
}

使用 DbModelBuilder 我有以下 Fluent API 代码:

EntityTypeConfiguration<Parent> adrInEgrul 
    = modelBuilder.Entity<Parent>();
adrInEgrul.HasKey(x => x.ID);
adrInEgrul.HasOptional(x => x.Child1)
    .WithOptionalPrincipal();
adrInEgrul.HasOptional(x => x.Child2)
    .WithOptionalPrincipal();

所有这些都给了我以下表格:

但我确实需要以下这些:

只要修复 Fluent API 部分,我就会很高兴得到我想要的东西,但不知道该怎么做(如果可能的话)。
将不胜感激。

【问题讨论】:

  • 只需将public int Child1Id {get;set;} 和第二个添加到父级!并去掉流利的代码

标签: c# entity-framework ef-fluent-api


【解决方案1】:

在 callum-linington 发表评论后,我想出了以下 Fluent API 代码,它完成了工作。

EntityTypeConfiguration<Parent> adrInEgrul 
    = modelBuilder.Entity<Parent>();
adrInEgrul.HasKey(x => x.ID);
adrInEgrul.HasOptional(x => x.Child1);
adrInEgrul.HasOptional(x => x.Child2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    相关资源
    最近更新 更多