I seem to be in the impossible situation whereby I need my objects to return the same hashcode before they're saved, after they're saved and when they're loaded in a new session.
I currently have the following (inadequate) GetHashCode() implementation:
Code:
public override int GetHashCode()
{
if (_ID == Guid.Empty)
return base.GetHashCode();
return _ID.GetHashCode();
}
This will clearly return a different value before and after object persistence. This is a problem because my object model is rich with HashedSet properties which require objects to have an immutable hashcode.
The following example should illustrate my problem:
Code:
Blog b = new Blog();
Post p = new Post();
b.Posts.Add(p);
Console.WriteLine(b.Posts.Contains(p)); //True
Save(b);
Console.WriteLine(b.Posts.Contains(p)); //False
Is my only option to move to assigned IDs that are created in the constructor of my domain objects? I seem to remember reading somewhere that there are implications with using assigned IDs when it comes to NH knowing if child objects have been previously saved.