【问题标题】:EF 6.0 - Map complex type to same table as parent propertyEF 6.0 - 将复杂类型映射到与父属性相同的表
【发布时间】:2018-09-05 17:41:31
【问题描述】:

我看过以下内容:

Entity framework code first map multiple complex types of the same type to a table

给出示例代码:

[Table("TXLifeRequest", Schema = "txlife")]
public partial class TXLifeRequest
{
    public virtual OLI_LU_BOOLEAN PendingResponseOK { get; set; }
    ...
}

[Table("OLI_LU_BOOLEAN", Schema = "txlife")]
public partial class OLI_LU_BOOLEAN {

    public string tc { get; set; }

    public string Value { get; set; }
}

我想构造数据库,使OLI_LU_BOOLEAN 不在新表中,而是在TXLifeRequest 表中作为TXLifeRequest.PendingResponseOK_tcPendingResponseOK _Value 之类的两个新列。

现有上下文中没有流畅的代码。有没有办法通过 fluent 或 attrubutes 来做到这一点,以便类结构完整但表被合并?

更新:

我尝试了以下方法,但它为所有 OLI_LU_BOOLEAN 属性创建了一个新表 TXLifeRequest1。我如何将这些指定为同一张表的属性?

modelBuilder.ComplexType<OLI_LU_BOOLEAN>()

CreateTable("imsparamed.TXLifeRequest1",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    PendingResponseOK_Value = c.String(),
                    PendingResponseOK_Id = c.Int(nullable: false)

                })

【问题讨论】:

    标签: entity-framework-6 ef-fluent-api


    【解决方案1】:

    解决方法是创建一个复杂类型:

    modelBuilder.ComplexType<OLI_LU_BOOLEAN>().Ignore(i => i.Value);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多