使用FluentNHibernate在SaveOrUpdate上没有任何反应

时间:2009-06-02 20:49:50

标签: nhibernate fluent-nhibernate

使用带有FluentNHibernate的SaveOrUpdate方法更新实体时没有任何反应。 Flush确实有效,但由于现有的存储库基础结构,我想使用SaveOrUpdate。可能是什么问题?

配置:

sessionFactory = Fluently.Configure()
    .Database(MsSqlConfiguration
        .MsSql2005
            .ConnectionString(c => c.FromConnectionStringWithKey("repository")))
        .Mappings(m => m.FluentMappings
            .AddFromAssemblyOf<InvoiceMap>())
    .BuildSessionFactory();

映射:

public InvoiceMap()
{
    Id(x => x.InvoiceID, "InvoiceID");
    Map(x => x.InvoiceNumber);
    Map(x => x.InvoiceDate);
    Map(x => x.Company).CustomTypeIs<CompanyType>();
    Map(x => x.TransactionNumber).CustomTypeIs<TransactionNumberType>();
    Map(x => x.LongAddressBookNumber);
    Map(x => x.PurchaseOrderNumber);
    Map(x => x.ReceivedDateTime);
    Map(x => x.OCR);
    Map(x => x.DocumentNumber);
    Map(x => x.DocumentType);
    Map(x => x.PaymentStatus).CustomTypeIs<PaymentStatusType>();
    HasMany(x => x.Attestations)
        .KeyColumnNames.Add("InvoiceID")
        .Inverse()
        .Cascade.AllDeleteOrphan()
        .AsBag();
    HasMany(x => x.AttestationRequests)
        .KeyColumnNames.Add("InvoiceID")
        .Inverse()
        .Cascade.AllDeleteOrphan()
        .AsBag();
    HasMany(x => x.States)
        .KeyColumnNames.Add("InvoiceID")
        .Inverse()
        .Cascade.AllDeleteOrphan()
        .AsBag();
}

public AttestationMap()
{
    Id(x => x.ID, "AttestationID");
    Map(x => x.ReceivedAt);
    Map(x => x.IsInvalid, "Invalid");
    Map(x => x.InvalidationReason);
    Map(x => x.FileName);
    Map(x => x.FileData);
    References<EmployeeSnapshot>(x => x.Certifier, "Certifier")
        .Cascade.All()
        .FetchType.Join();
    References<Invoice>(x => x.Owner, "InvoiceID");
}

public AttestationReminderMap()
{
    Id(x => x.ID, "AttestationReminderID");
    Map(x => x.CC)
        .CustomTypeIs<RecipientType>();
    Map(x => x.Message);
    Map(x => x.SentAt);
    References<AttestationRequest>(x => x.Owner, "RequestID");
}

有什么想法吗?

谢谢, 的Kristoffer

2 个答案:

答案 0 :(得分:2)

当你说什么都没有发生时,你的意思是说没有冲洗的数据库没有任何反应吗?

如果是这样,那就是预期的行为。 Flush告诉NHib将其在内存中的更改写入DB。

答案 1 :(得分:0)

不知何故,我设法将会话的FlushMode设置为Never。正如Chad向我所描述的那样,它需要明确调用Flush。当FlushMode保留默认值并使用Transaction时,实体将按预期更新。