Father father = BL.GetFatherById(1);
Product product = BL.GetByID(123);
(father.Products[553] == product)
product.delete = true;
father.Products[553].delete == false !!??
why is that ?
aren't they connected ?? its the same object.
Father father = BL.GetFatherById(1);
Product product = BL.GetByID(123);
(father.Products[553] == product)
product.delete = true;
father.Products[553].delete == false !!??
why is that ?
aren't they connected ?? its the same object.
As you can read in section 10.3 of the NHibernate reference manual database identity and CLR object identity are equivalent per session.
Therefore Object.ReferenceEquals(foo, bar)
will yield true
if and only if foo
and bar
are attached to the same session and map to the same database row. Be careful when using ==
for comparing object identity - the operator may have been overloaded (but you should usually know that).
In consequence you should always get the same object no matter what query you use for the object as long as you stay within the same session. Are you using multiple sessions? Maybe a Unit of Work pattern and you are comparing objects returned from to different units of work?
First, let me tell you that what you are doing is HORRIBLE. What does this actually mean
father.Products[553] == product;
Unless you have coded a custom collection, which I doubt you did there is no way that would work.
So
Take a look here how to do it (disregard the actual question)
http://stackoverflow.com/questions/2783622/how-to-map-it-hasone-x-references/2803860#2803860