实体框架6 - 该类型已配置为实体类型。它不能重新配置为复杂类型

时间:2015-08-07 10:21:15

标签: c# entity-framework complextype

我有一个实体,我已经做了一些小改动。我已经将外键设为不可空并且是必需的。 当我来创建实体框架迁移时,我收到错误:

  

类型'付款'已被配置为实体类型。它   不能重新配置为复杂类型。

我不明白为什么会这样。我没有将任何类定义为复杂类型。 我使用的是Enum,但这一直存在,以前从未出现过问题,并且在EF6下得到支持。

项目本身仍然很好。

这是造成问题的Payment类。

public partial class Payment
{
    public int payment_ID { get; set; }
    public int order_ID { get; set; }
    public PaymentTypeEnum paymentType_ID { get; set; }
    public string cc_response_ReceiptNo { get; set; }
    public string cc_response_QSIResponseCode { get; set; }
    public string cc_response_QSIResponseDescription { get; set; }
    public string cc_response_TransactionNo { get; set; }
    public string cc_response_BatchNo { get; set; }
    public DateTime? cc_response_expected { get; set; }
    public bool? cc_response_checked { get; set; }
    public DateTime? paymentReceived { get; set; }
    public int? paymentAmountUnits { get; set; }
    public string paymentNotes { get; set; }
    public string cc_GatewayIdent { get; set; }
    public virtual Order Order { get; set; }
    public virtual PaymentType PaymentType { get; set; }
    public virtual ICollection<CreditNote> CreditNotes { get; set; }
}

映射信息

 public class tbl_paymentMap : EntityTypeConfiguration<Payment>
{
    public tbl_paymentMap()
    {
        // Primary Key
        this.HasKey(t => t.payment_ID);

        // Properties
        this.Property(t => t.cc_response_ReceiptNo)
            .HasMaxLength(12);

        this.Property(t => t.cc_response_QSIResponseCode)
            .HasMaxLength(2);

        this.Property(t => t.cc_response_QSIResponseDescription)
            .HasMaxLength(150);

        this.Property(t => t.cc_response_TransactionNo)
            .HasMaxLength(21);

        this.Property(t => t.cc_response_BatchNo)
            .HasMaxLength(21);

        this.Property(t => t.paymentNotes)
            .HasMaxLength(100);

        this.Property(t => t.cc_GatewayIdent)
            .HasMaxLength(50);

        // Table & Column Mappings
        this.ToTable("tbl_payment");
        this.Property(t => t.payment_ID).HasColumnName("payment_ID");
        this.Property(t => t.order_ID).HasColumnName("order_ID");
        this.Property(t => t.paymentType_ID).HasColumnName("paymentType_ID");
        this.Property(t => t.cc_response_ReceiptNo).HasColumnName("cc_response_ReceiptNo");
        this.Property(t => t.cc_response_QSIResponseCode).HasColumnName("cc_response_QSIResponseCode");
        this.Property(t => t.cc_response_QSIResponseDescription).HasColumnName("cc_response_QSIResponseDescription");
        this.Property(t => t.cc_response_TransactionNo).HasColumnName("cc_response_TransactionNo");
        this.Property(t => t.cc_response_BatchNo).HasColumnName("cc_response_BatchNo");
        this.Property(t => t.cc_response_expected).HasColumnName("cc_response_expected");
        this.Property(t => t.cc_response_checked).HasColumnName("cc_response_checked");
        this.Property(t => t.paymentReceived).HasColumnName("paymentReceived");
        this.Property(t => t.paymentAmountUnits).HasColumnName("paymentAmountUnits");
        this.Property(t => t.paymentNotes).HasColumnName("paymentNotes");
        this.Property(t => t.cc_GatewayIdent).HasColumnName("cc_GatewayIdent");

        // Relationships
        this.HasRequired(t => t.Order)
            .WithMany(t => t.Payments)
            .HasForeignKey(d => d.order_ID);
        this.HasRequired(t => t.PaymentType)
            .WithMany(t => t.Payments)
            .HasForeignKey(d => d.paymentType_ID);
   }
}

2 个答案:

答案 0 :(得分:1)

好的,结果证明这是我自己做的一个奇怪的事情。 在我的支付类旁边有一个CreditNote类。 您可以在我原来的问题中看到一张付款可能有很多信用票据。

除此之外,付款和信用票据都单独引用了订单。

在执行某些规范化的过程中,我从信用票据类中删除了订单类的链接。在修复随之而来的错误的同时,我找到并替换了一些beserk,并在信用票据映射中无意中执行了它。

因此

    public tbl_creditnoteMap()
    {
       this.Property(t => t.order_ID).HasColumnName("order_ID");

成了

    public tbl_creditnoteMap()
    {
       this.Property(t => t.Payment.order_ID).HasColumnName("order_ID");

实际上它应该完全被删除。 这显然打破了幕后的事情。

答案 1 :(得分:0)

将以下内容添加到解决您的问题的OnModelCreating中我认为:

modelBuilder.Ignore<YourClassNameorEntityName>();