Kristoffer
Kristoffer

Reputation: 1653

Nothing happens on SaveOrUpdate using FluentNHibernate

Nothing happens when updating an entity using the SaveOrUpdate method with FluentNHibernate. Flush does work but I want to use SaveOrUpdate due to existing repository infrastructure. What could be the problem?

Configuration:

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

Mappings:

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");
}

Any ideas?

Thanks, Kristoffer

Upvotes: 0

Views: 4639

Answers (2)

Kristoffer
Kristoffer

Reputation: 1653

Somehow I had managed to set the session's FlushMode to Never. It resulted in the need for an explicit call to Flush, as Chad described to me. When FlushMode left to it default value, and using an Transaction, the entity is updated as expected.

Upvotes: 0

Chad Ruppert
Chad Ruppert

Reputation: 3680

When you say nothing happens, do you mean that nothing happens to the DB without a flush?

If so, that is expected behavior. Flush tells NHib to write the changes it has in memory to the DB.

Upvotes: 2

Related Questions