--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.
abstract public class EntityBase
{
public virtual Guid Id { get; protected set; }
public virtual int Version { get; set; }
// Two entities are considered equal if their Ids are the same
public override bool Equals(object obj)
{
if (obj == null)
return false;
var other = obj as EntityBase;
if (other == null)
return false;
if (Id.Equals(Guid.Empty))
return ReferenceEquals(this, obj);
return Id.Equals(other.Id) && Version == other.Version;
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
public abstract class RegistryBase : EntityBase
{
// -- additional properties omitted --
public virtual short Priority { get; protected set; }
}
public abstract class Case : RegistryBase
{
// -- additional properties ommited --
public virtual IList<Specimen> Specimens { get; set; }
}
private Specimen CreateSpecimen() {
return new Specimen() { /* additional properties */, Case = original }
}
using (var session = DatabaseSetUpFixture.SessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
Case original = AddSampleCase(session);
original.Specimens = new List<Specimen>() {
new Specimen () { /* additional properties */, Case = original }
};
session.Flush(); // Save the changes
session.Clear(); // Evict all entities from the session
Case newVersion = session.Get<Case>(original.Id); // Get the DB version
newVersion.Specimens.Clear(); // Remove all the specimens
session.Update(newVersion);
session.Flush(); // StaleStateException here :S
// ...
tx.Rollback(); // Leave the test DB untouched
}
}Thanks!
You received this message because you are subscribed to a topic in the Google Groups "nhusers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhusers/w9dUy2WHUKU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nhusers+u...@googlegroups.com.