I am using c# with Fluent NHibernate and auto mapping.
Here is some code (truncated for clarity), then I'll explain the problem.
public class Company
{
public virtual string Description { get; set; }
}
public class Stock
{
public virtual Product Product { get; set; }
public virtual Company Company { get; set; }
}
Mapping
mappings.Conventions.Add<CascadeConvention>()
.Conventions.Add<CustomForeignKeyConvention>()
.Conventions.Add<HasManyConvention>()
.Conventions.Add<VersionConvention>()
CascadeConvention
just sets everything to All.CustomForeignKeyConvention
removes the _id that NHibernate usually appends to foreign key id columns.HasManyConvention
sets allHasMany
's to inverse.VersionConvention
convertion looks like this:instance.Column("Version");
instance.Default(1);
The problem is that when I insert a new stock record, Nhibernate also updates the version number on the related Company
.
If I had an IList<Stock>
property on the Company
then that would make sense but I don't.
I've done a lot of reading around:
- NHibernate emitting extraneous update statements regardless of proper Inverse (fluent nhibernate) settings on relations
- Cascade Save-Update in NHibernate and version column
- NHibernate Reference - Chapter 17. Example: Parent/Child
- Ayende @ Rahien - NHibernate Mapping
From these, I've tried a whole bunch of things including adding .Not.OptimisticLock()
all over the place. I even added an IList<Stock>
property on Company
so that I could specifically set it as Inverse
, Not.OptimisticLock
, etc. Nothing I do seems to make any difference.