2

我有一个映射如下:

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 CASCADEDDL。我做错了什么或不完整?

4

1 回答 1

1

NH 支持许多不同的 RDBMS 并且已经支持了很长时间,因此默认是在代码中进行。另一方面,FNH 开始实现最常见的功能,而这不是。而且仍然没有人提出问题来支持这项 NH 功能。也很难说,因为在映射中方言是未知的,因此它不知道是否支持该功能。

于 2012-08-23T13:52:10.980 回答