Loading...

nhusers@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[nhusers] Session.Merge [EMAIL PROTECTED] Thu Feb 25 08:00:11 2010

I am not getting the expected behaviour from Session.Merge and
wondered if I am doing something wrong.

I have an object such as

public class SomeObject
{
 public virtual int id { get;set;}
 public virtual string name { get;set;}
 public virtual DateTime Added { get; set;} // not null
}

I then want to create a new object, with an ID. The object might exist
in the database with the same ID, and if this is the case I would like
to merge the new object with the one in the database and then save it.

I had something like this

var someObject = new SomeObject
{
 id = 1,
 name = "test"
};
var newSomeObject = session.Merge(someObject);
session.Flush();

When I run it, I can see from NHProf, that the object does exist in
the database and its being selected but it is never merged. All I get
back in newSomeObject is my original new object. When I flush or
commit, I then get an error because Added is null because the objects
haven't been merged.

Any ideas what I might be doing wrong?

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.