1
votes

I have a collection mapped as a query only property following Ayende's example. My mapping is:

HasMany<Employee>(Reveal.Member<Company>("_employees")).Access.None();

This worked fine, except when I load a Company the foreign key Employee.CompanyId is updated to null. This occurs even if I don't update Company and the generated SQL only includes the CompanyId in the update list even though I have not mapped Employee to update changed properties only.

I tried using NoOp (they're synonyms I think) and declaring the employees collection as a public property instead of a private field. I was finally able to fix it by changing the mapping to:

HasMany(Reveal.Member("_employees")).Access.None().Not.KeyUpdate();

What is the purpose of KeyUpdate and what is the equivalent XML mapping? Why is it needed for a query only property? My assumption was that setting access to none or noop would prevent any changes.

1
According to fluentnhibernate.org/api/FluentNHibernate.Mapping/OneToManyPart1.htm (sorry, the link doesn't come through with ``), it designates that the key can be updated. I'm not sure how that has anything to do with what you're seeing, though. - Jay
This is still a "bug" in NH 3.2. - Jamie Ide

1 Answers

1
votes

Jamie

You can generate the hbms from your AutoPersistenceModel and have a look at the xml if you are still interested. Just something like

model.CompileMappings(); 
model.WriteMappingsTo(outputDir);

As an aside, have you had a look yet @ ConfOrm. I suspect this will gain increased traction given the dev, but haven't spent much time with it yet.

HTH,
Berryl