Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try using the overloaded PersistenceSpecification constructor that takes an IEqualityComparer to compare the child objects (AssociatedGuardian, AssociatedStudent). The persistence specification test compares two different references (original and retrieved), so they will have different hash codes with your implementation. As I understand it, comparisons made using an IEqualityComparer firsts compare the hash codes then check Equals if the hash code matches. My guess is that PersistenceSpecification is wrapping the Equals call in an IEqualityComparer implementation.</p> <p>I use a utility class to make this easier:</p> <pre><code>public class PersistenceSpecificationEqualityComparer : IEqualityComparer { private readonly Dictionary&lt;Type, Delegate&gt; _comparers = new Dictionary&lt;Type, Delegate&gt;(); public void RegisterComparer&lt;T&gt;(Func&lt;T, object&gt; comparer) { _comparers.Add(typeof(T), comparer); } public bool Equals(object x, object y) { if (x == null || y == null) { return false; } var xType = x.GetType(); var yType = y.GetType(); // check subclass to handle proxies if (_comparers.ContainsKey(xType) &amp;&amp; (xType == yType || yType.IsSubclassOf(xType))) { var comparer = _comparers[xType]; var xValue = comparer.DynamicInvoke(new[] {x}); var yValue = comparer.DynamicInvoke(new[] {y}); return xValue.Equals(yValue); } return x.Equals(y); } public int GetHashCode(object obj) { throw new NotImplementedException(); } } </code></pre> <p>Usage:</p> <pre><code>var comparer = new PersistenceSpecificationEqualityComparer(); comparer.RegisterComparer((Guardian x) =&gt; x.Id); comparer.RegisterComparer((Student x) =&gt; x.Id); // etc. new PersistenceSpecification&lt;StudentGuardianAssociation&gt;(Session, comparer) .CheckProperty(x =&gt; x.RelationShipToStudent, 1) .CheckReference(x =&gt; x.AssociatedStudent, student) .CheckReference(x =&gt; x.AssociatedGuardian, guardian) .VerifyTheMappings(); </code></pre> <p>EDIT:</p> <p>I think I see the problem: guardian and student are not persisted in the session and there's no cascade that would do it automatically. Saving those objects before running the PersistenceSpecification should fix it. You can see the code for the CheckValue method in <a href="https://stackoverflow.com/questions/1776120/fluent-nhibernate-persistencespecification-component-and-reference-tests">this answer</a>. In looking at your question again, the error message states "but got '' of type 'Pats.DataTransfer.Student'" indicating that the value is null.</p> <p>Assuming that's the solution, I am curious if you still need the IEqualityComparer. Profiling using a tool such as <a href="http://nhprof.com/" rel="nofollow noreferrer">NHProf</a> would have caught this quickly because you would see the nulls in the insert.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload