级联删除与流利的nhibernate

时间:2012-08-20 15:18:35

标签: c# postgresql fluent-nhibernate nhibernate-mapping

我的映射如下:

public class InvoiceDetailMapping : ClassMap<InvoiceDetail>
{
    public InvoiceDetailMapping()
    {
        Id(x => x.DetailId)
            .GeneratedBy.Guid();

        Map(x => x.Account);
        Map(x => x.Credit);
        Map(x => x.Debit);
        Map(x => x.PayType);
        Map(x => x.RowNumber);

        References<InvoiceItem>(x => x.Invoice, "InvoiceItemId")
            .Cascade.All();

    }
}

public class InvoiceItemMapping : ClassMap<InvoiceItem>
{
    public InvoiceItemMapping()
    {
        Id(x => x.RecordId)
            .GeneratedBy.Guid();

        Map(x => x.BatchId);
        Map(x => x.Description);
        Map(x => x.DocumentDate);
        Map(x => x.DocumentId);
        Map(x => x.DocumentType);
        Map(x => x.FileId);
        Map(x => x.FileName);
        Map(x => x.InvoiceAmount);
        Map(x => x.LocationCode);
        Map(x => x.PayDate);
        Map(x => x.PaymentTerms);
        Map(x => x.PayNumber);
        Map(x => x.PurchaseAmount);
        Map(x => x.PurchaseInvoiceAmount);
        Map(x => x.InvoiceId);
        Map(x => x.Submittable);
        Map(x => x.SubmittedBy);
        Map(x => x.SubmittedTimeStamp);
        Map(x => x.TaxForm1099Amount);
        Map(x => x.TroubleClass);
        Map(x => x.VendorDocNumber);
        Map(x => x.VendorId);
        Map(x => x.PersistedTimeStamp)
            .CustomType<UtcDateTimeType>()
            .Generated.Insert();

        HasMany<InvoiceDetail>(x => x.InvoiceDetails)
            .Inverse()
            .Cascade.All()
            .KeyColumn("InvoiceItemId");
    }
}

...但是当我将它应用于我的PostgreSQL数据库时,它会为InvoiceDetail创建以下SQL:

CREATE TABLE "InvoiceDetail"
(
  detailid uuid NOT NULL,
  account character varying(255),
  credit numeric(19,5),
  debit numeric(19,5),
  paytype integer,
  rownumber integer,
  invoiceitemid uuid,
  CONSTRAINT "InvoiceDetail_pkey" PRIMARY KEY (detailid ),
  CONSTRAINT fkd8588014e9009e93 FOREIGN KEY (invoiceitemid)
      REFERENCES "InvoiceItem" (recordid) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION

请注意ON UPDATE NO ACTION ON DELETE NO ACTION行。我原以为Cascade.All()指令会创建一个ON UPDATE CASCADE ON DELETE CASCADE DDL。我做错了什么或不完整?

1 个答案:

答案 0 :(得分:1)

NH支持许多不同的RDBMS并且已经很长时间了,因此默认是在代码中执行它。另一方面,FNH首先实现了这个不是最常见的功能。并且仍然没有人提出支持这个NH功能的问题。此外,很难说,因为在映射中,Dialect不为人所知,因此无法知道该功能是否得到支持。