Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you either need to implement the object.Equals() method on the relevant entities, or implement an IEqualityComparer and inject it when you construct the PersistenceSpecification.</p> <p>For example:</p> <pre><code>public class A { private int Id { get; set; } public virtual B B_Member { get; set; } public class Map : ClassMap&lt;A&gt; { public Map() { Id(x =&gt; x.Id); References(x =&gt; x.B_Member); } } } public class B { private int Id { get; set; } public virtual string BString { get; set; } public class Map : ClassMap&lt;B&gt; { public Map() { Id(x =&gt; x.Id); Map(x =&gt; x.BString); } } /// remove this method to have the verification fail public override bool Equals(object obj) { var lhs = obj as B; if (lhs == null) return false; return BString == lhs.BString; } } [Test] public void Verify() { var fcfg = Fluently.Configure() .Database(SQLiteConfiguration.Standard.UsingFile("testdb.sqldb")) .Mappings(mc =&gt; { mc.FluentMappings.Add(typeof (A.Map)); mc.FluentMappings.Add(typeof (B.Map)); }) .ExposeConfiguration(cfg =&gt; new SchemaExport(cfg).Execute(true, true, false)); var sess = fcfg.BuildSessionFactory().OpenSession(); new PersistenceSpecification&lt;A&gt;(sess) .CheckReference(x =&gt; x.B_Member, new B() {BString = "hi"}) .VerifyTheMappings(); Assert.Throws&lt;ApplicationException&gt;( () =&gt; new PersistenceSpecification&lt;A&gt;(sess, new AlwaysFalseEqualityComparer()) .CheckReference(x =&gt; x.B_Member, new B() {BString = "az"}) .VerifyTheMappings()); } </code></pre> <p>Note also that the relevant FNH code for each property comparison is (compliments of reflector):</p> <pre><code> internal virtual void CheckValue(object target) { bool areEqual; object actual = this.property.GetValue(target, null); if (this.entityEqualityComparer != null) { areEqual = this.entityEqualityComparer.Equals(this.propertyValue, actual); } else { areEqual = this.propertyValue.Equals(actual); } if (!areEqual) { throw new ApplicationException(string.Format("Expected '{0}' but got '{1}' for Property '{2}'", this.propertyValue, actual, this.property.Name)); } } </code></pre> <p>Certainly that that exception seems to match the ones you are experiencing.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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