tags:

views:

166

answers:

1

I'm having trouble with saving an object into my database using NHibernate.

My code looks like this:

Image image = new Image { Url = 'test.jpg' };
Product product1 = new Product { Name = 'MyProduct', Image = image };
Product product2 = new Product { Name = 'MyProduct2', Image = image };

MySession.Save(product1); // This also creates an Image record
MySession.Save(product2); // This creates another Image record even tho the data is exactly the same

I would like to prevent the image from being created twice. Is there a standard NHibernate solution for that or do i have to create a custom Save() method for the Product class?

A: 

After a long search i found something about implementing the Equals() method for my entity classes so that NHibernate can compare them. Maybe this is the solution to my problem.

Ruud