Friday 15 May 2015

c# - Nhibernate updating version column on foreign key entity -


I am using CH #, on NHibernate and automapping.

Here's some code (small for clarity), then I interpret the problem.

  public class company {public virtual string description {get; Set; }} Public class stock {public virtual product product {get; Set; } Public Virtual Company Company {Received; Set; }} << / Strong>    
  • Cascade Convention just sets everything up.
  • CustomForeignKeyConvention removes the NID that the NHibernate is usually enclosed in the Foreign Key ID column.
  • HasManyConvention All HasMany

    version version conversion looks like this: < / P>

    example. Column ("version");

    Example. Default (1);

    The problem is that when I insert a new stock record, Nhibernate also updates the version number related to the company . If I have IList & lt; Stock & gt; If property is on company then it will be prudent but I do not.

    I have done a lot of reading from:

    • Of these, I have tried things like adding 'code'. No. Optimistics Lock () I also have the IList & lt; Stock & gt; The company on the property is also added, so that I specially give it inverse , Not.opimisticLock , etc. I do not make any difference to anything.

      We finally did not have a session-per-request pattern, it is not certain why this was going wrong Or why he decided it. Without success, I have written several unit tests to try and reproduce behavior in a more controlled environment.

      In any case, it works now. Good reason: session-per-request is often the best practice method of managing NHibernate sessions in web applications.

No comments:

Post a Comment