Note that there are some explanatory texts on larger screens.

plurals
  1. POdouble order by in Dynamics CRM 2011 Linq query
    primarykey
    data
    text
    <p>I'm developing a survey module for CRM 2011, where a CRM user can make a survey with multiple questions of different types and ask contacts to answer them using a dynamic web page on Azure. I have completed about 90% of it so far and just need to add a few minor changes involving data management.</p> <p>The part I'm currently optimizing involves sorting my questions. I have 2 entities in CRM: surveyquestion and question. question refers to an actual question in the survey, while surveyquestion is an N-N relationship entity with a few additional fields, so we can reuse questions in different surveys. I have a field "groep" in "question" which is used to indicate whether a question should be grouped with another question on the form. I have another field, "volgorde" in "surveyquestion", which is used to indicate the order of the questions. I wish to show all questions with the same "group" together, and then order any questions inside groups (and ungrouped questions as a separate group) by the sortorder field. So I basically need to order on 2 fields in 2 different tables, which seems to be quite tricky.</p> <p>This is the code I'm currently using. I'm getting a nullreferenceexception on the join for vraaglist, which is weird because both vr.Id and ev.slfn_vraag.Id have data in the relevant rows. I don't think it's due to the orderby, because the commented code above works (but I cannot simply add ev.volgorde to my orderby because he complains about that.</p> <pre><code>public List&lt;slfn_vraag&gt; GetVragenforEnquete(Guid enGuid) { //List&lt;slfn_vraag&gt; vraaglist = (from vr in _oContext.slfn_vraagSet // join ev in _oContext.slfn_enquetevraagSet on vr.Id equals ev.slfn_vraag.Id // orderby vr.slfn_Groep // where ev.slfn_enquete.Id == enGuid // select vr).ToList(); IQueryable&lt;slfn_enquetevraag&gt; enquetevraaglist = (from ev in _oContext.slfn_enquetevraagSet orderby ev.slfn_volgorde where ev.slfn_enquete.Id == enGuid select ev); List&lt;slfn_vraag&gt; vraaglist = (from vr in _oContext.slfn_vraagSet join ev in enquetevraaglist on vr.Id equals ev.slfn_vraag.Id orderby vr.slfn_Groep select vr).ToList(); return vraaglist; } </code></pre> <p>The code compiles without errors, but when i run it, I get a NullReferenceException on the question query. does anyone have any ideas on how to fix this?</p> <p>edit: exception details from VS2012 as requested below.</p> <pre><code> System.NullReferenceException occurred HResult=-2147467261 Message=De objectverwijzing is niet op een exemplaar van een object ingesteld. Source=Microsoft.Xrm.Sdk StackTrace: bij Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateJoin(QueryExpression qe, IList`1 methods, Int32&amp; i, Projection&amp; projection, List`1&amp; linkLookups) bij Microsoft.Xrm.Sdk.Linq.QueryProvider.GetQueryExpression(Expression expression, Boolean&amp; throwIfSequenceIsEmpty, Boolean&amp; throwIfSequenceNotSingle, Projection&amp; projection, NavigationSource&amp; source, List`1&amp; linkLookups) bij Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression) bij Microsoft.Xrm.Sdk.Linq.QueryProvider.GetEnumerator[TElement](Expression expression) bij Microsoft.Xrm.Sdk.Linq.Query`1.GetEnumerator() bij System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) bij System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) bij Enquete_Webform.Data.EnqueteGenerator.GetVragenforEnquete(Guid enGuid) in e:\VS\tfs_products\MS CRM\2011\Enquete\Enquete_Webform\Enquete_Webform\Data\EnqueteGenerator.cs:regel 49 InnerException: </code></pre>
    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. 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