c# - NHibernate Caching Objects Based on Parent Class's ID -


I have the following definitions for animal and dog type: Note that the ID for the object is AnimalID:

  & lt; Class name = "Animal" table = "Animals" & gt; & Lt; Id name = "id" type = "System.Int32" column = "AnimalID" & gt; & Lt; Generator class = "identity" /> & Lt; / Id & gt; & Lt; Property Name = "Isbag" column = "Isbag" type = "System.Bool" no-null = "true" /> & Lt; / Square & gt; & Lt; Attached sub-class name = "dog" table = "dogs" expanded = "animal" & gt; & Lt; Key column = "AnimalID" /> & Lt; Property Name = "Owner ID" column = "Owner ID" type = "System.Int32" non-null = "true" /> & Lt; Property Name = "Eyesstong" column = "Iststong" type = "System.Bool" non-cord = "true" /> & Lt; Joined in / subclass & gt;  

Let's say I have the following information in my database:

  Animals in the table: AnimalID IsBig -------- --- - 10 true dogs in table: AnimalID owner IIStrtr -------- ------- -------- 10 1 true 10 2 incorrect  

First of all, I ask for the dog where the owner ID = 1 In the same session, where I own the dog = 2, due to the session cache of NHibernate, the second question gives a dog object where the owner = 1 and IsStrong = true, where it should return a dog object where the owner = 2 And IsStrong = False.

NHibernate automatically caches the object with its ID (primary key) column, so the dog's request ends up recovering the object with the same key for the second time.

Any better suggestions?

You should make sure that you are using different keys for different instances. In fact you are violating this rule: The dog table exposes parts of two examples sharing the same key .

If dogs should be marked as primary key, but in your case it is not. Area is marked as PK, you can not get the content at all.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -