Note that there are some explanatory texts on larger screens.

plurals
  1. PONhibernate/Linq: NHibernate.QueryException : could not resolve property: Profile.class of: MyNamespace.MyObject
    text
    copied!<p>I'm having an issue with my linq query. I am trying to filter objects based on selected values. We use a query model which returns a System.Linq.Expressions.Expression and uses it to create an nhibernate query. Here is my linq expression.</p> <pre><code>x =&gt;(request.InitialLoad || (!request.InitialLoad &amp;&amp; (Enum.GetValues(typeof(MyType)).Length == request.MyTypes.Length || (Enum.GetValues(typeof(MyType)).Length != request.MyTypes.Length &amp;&amp; ((request.MyTypes.Contains((int)MyType.Referrals) &amp;&amp; x.Post.PostType == StatusPostType.Referral) || (request.MyTypes.Contains((int)MyType.Businesses) &amp;&amp; x.Post.Profile is BusinessProfile) || (request.MyTypes.Contains((int)MyType.Members) &amp;&amp; x.Post.Profile is UserProfile) ) ) ) ) ) &amp;&amp; x.Profile.Equals(request.Profile); </code></pre> <p>The mappings (we are using fluent) Look like this:</p> <p>MyObject (Post property):</p> <pre><code>References(x =&gt; x.Post, "PostId"); </code></pre> <p>MyObject.Post (Profile property):</p> <pre><code>References(x =&gt; x.Profile, "ProfileId"); </code></pre> <p>When I change <code>x.Post.Profile is SomeType</code> to <code>x.Post.Profile.GetType() == typeof(SomeType)</code> it throws a different error, which is </p> <blockquote> <p>System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index</p> </blockquote> <p>When I take out the type comparison boolean expressions and only leave in the Referrals expression, it works fine for filtering only on that one option.</p> <p>The properties are not modified in any way by the model. They are virtual properties with the default get/set.</p> <p>Any ideas?</p>
 

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