|
Imagine you have a Entity called as "Person".
That business class has 5 properties. One of them is the primary key: ID, int, not null
There is a property called "Reports". Its data is constructed by a relationship with two other tables.
On the business rule has as necessity a collections List with several records of Person class. A very possible result would be the following:
(Here is showed just 3 Person's properties)
ID | Reports | Date
1 | 20 | 04-01-2007
3 | 10 | 04-25-2007
1 | 30 | 04-6-2007
1 | 20 | 04-15-2007
3 | 10 | 04-10-2007
6 | 10 | 04-08-2007
as you can see...there are three times the ID 1, and twice ID 3.
How does NHibernate get that result?
The steps would be something like that:
1. Gets object's ID with value 1 => put it in the Session;
2. Gets object's ID with value 3 => put it in the Session;
3. Gets object's ID with value 1 ? it already is in the Session, Use it;
4. Gets object's ID with value 1 ? it already is in the Session, Use it;
5. Gets object's ID with value 3 ? it already is in the Session, Use it;
6. Gets object's ID with value 6 => put it in the Session;
for ids 1 and 3..their records are different..
But as NHibernate's logic firstly looks for it in the Session...the records always will be the same, even thought the DataAdapter has records that aren't the same.
Reports and Date are aliases from other columns.
How to avoid that?
|