Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery/Mapping problem using NHibernate
    primarykey
    data
    text
    <p>I'm experiencing a problem with a certain query I'm attempting against a simple joined pair of classes, represented in my example below:</p> <p>Classes:</p> <pre><code>public class ParentClass { public virtual Guid ParentClassId { get;set;} public virtual ChildClass ChildClassRef { get;set;} } public class ChildClass { public virtual Guid ChildClassId { get;set;} public virtual string ChildCode { get;set;} } </code></pre> <p>Fluent Mappings:</p> <pre><code>public class ParentClassMap : ClassMap&lt;ParentClass&gt; { public ParentClassMap() { Id(x =&gt; x.ParentClassId).GeneratedBy.Guid(); References&lt;ChildClass&gt;(x =&gt; x.ChildClassRef, "ChildClassId").ForeignKey("ChildClassId").Fetch.Join(); } } public class ChildClassMap : ClassMap&lt;ChildClass&gt; { public ChildClassMap() { Id(x =&gt; x.ChildClassId).GeneratedBy.Guid(); Map(x =&gt; x.ChildCode).Not.Nullable(); } } </code></pre> <p>This fails:</p> <pre><code>DetachedCriteria criteria = DetachedCriteria.For(boType); criteria.Add(Expression.Eq("ChildClassRef.ChildCode", "ABC")); ICriteria runnableCriteria = detachedCriteria.GetExecutableCriteria(session); IList ilistResult = runnableCriteria.List(); </code></pre> <p>with error: "could not resolve property: ChildClassRef.ChildCode".</p> <p>However, this criteria works:</p> <pre><code>criteria.Add(Expression.Eq("ChildClassRef.ChildClassId", "931DAF7A-15D1-4B0B-8030-1C113BABC554")); </code></pre> <p>This, along with other evidence, suggests to me that my Fluent Reference mapping is correct (or maybe just slightly flawed). </p> <p>EDIT: Underlying tables:</p> <pre><code>ParentClass: ParentClassId, ChildClassId ChildClass: ChildClassId, ChildCode </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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