Mam Store
który zawiera listę Products
:Jak zapisać obiekt przejściowy, który już istnieje w sesji NHibernate?
var store = new Store();
store.Products.Add(new Product{ Id = 1, Name = "Apples" };
store.Products.Add(new Product{ Id = 2, Name = "Oranges" };
Database.Save(store);
Teraz chcę zmienić jedną z Products
, ale z nieustalonych podmiotu. Będzie to na przykład dane z poziomu przeglądarki internetowej:
// this is what I get from the web browser, this product should
// edit the one that's already in the database that has the same Id
var product = new Product{ Id = 2, Name = "Mandarin Oranges" };
store.Products.Add(product);
Database.Save(store);
Jednak starając się zrobić to w ten sposób daje mi błąd:
a different object with the same identifier value was already associated with the session
Powodem jest fakt, że zbiór store.Products
zawiera już podmiot o tym samym identyfikatorze. Jak obejść ten problem?
Czy próbowałeś session.Evict (produktu) przed zapisaniem po raz drugi? – mxmissile