czuroski
czuroski

Reputation: 4332

Duplicate records

I am using nHibernate for db persistence. I have a one-to-many relationship defined between 2 tables. When I query and try to get data, I am getting the correct number of rows from the "many" table, but the rows are duplicates of the first row returned.

table1 (one), table2 (many). I create a criteria query to get a certain record from table1. I then expect to get all associated records from table2. ie, table1 holds orders, table2 holds items. I query table1 to get an order which has 4 items. I expect to see each of those 4 items from table2, but all I am seeing is the 1st item repeated 4 times.

Does anyone have any idea what might be happening?

Upvotes: 0

Views: 789

Answers (2)

czuroski
czuroski

Reputation: 4332

I found the problem to be a composite key on table2. I included the composite-id mapping and it worked fine.

Thanks to the code here to get me through the Equals and GetHashCode errors.

Thanks

Upvotes: 1

Sly
Sly

Reputation: 15217

NHibernate performs join to execute your query. To get distinct results use DistinctEntityRootTransformer.

Upvotes: 0

Related Questions