title: Unable to create a constant value...Only primitive types or enumeration types are supported in this context
body: <p><strong>Error:</strong></p>
  
  <p>I'm getting the error mentioned above and the following is my stack trace:</p>
  
  <blockquote>
    <p>Unable to create a constant value of type
    'JackHenry.JHAKeys.Model.ADSENTDB.L_FORMS_SEL_APPLICANT'. Only
    primitive types or enumeration types are supported in this context.</p>
    
    <p>Source:   "mscorlib"</p>
    
    <p>at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32
    millisecondsTimeout, CancellationToken cancellationToken) at
    System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32
    millisecondsTimeout) at System.Threading.Tasks.Task.WaitAll(Task[]
    tasks) at
    Keys.BusinessLogic.Lending.Document.Fill.LoanFillService.FillLoanObject(String
    workID, Boolean documentSelection) in
    F:\JHA6\JHAKEYS\2018\Services\DEV\ArgoServices\Keys.BusinessLogic\Lending\Document\Fill\LoanFillService.cs:line
    422</p>
  </blockquote>
  
  <p>I've narrowed my problem down to the following linq statement:</p>
  
  <pre><code>var query = from t in ctx.L_FORMS_SELECTION
              where (ctx.L_FORMS_SEL_APPLICANT.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_APP_INSIDER.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_PROD_CODE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_PROD.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_QUEUE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_COLLAT.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_COLLAT_STATE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_COLLAT_VIEW.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_LOAN.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_LOAN_JURISDICTION.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_LOAN_PURPOSE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_REG.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_SUBSTITUTE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_CREDIT_INS.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_APP_MARITAL_STAT.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_APP_STATE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_RATE.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_COLLAT_COUNTY.Any(c =&gt; (c.form_id == t.form_id)) ||
              ctx.L_FORMS_SEL_LOAN_APPSOURCE.Any(c =&gt; (c.form_id == t.form_id)))
              &amp;&amp; t.shared_service_ind.ToUpper().Trim() == "E"
              select t;
  
  if ((query.FirstOrDefault() != null))
                      return true;
  </code></pre>
  
  <p>Obviously just trying to search through a bunch of tables to see if the value exists in any of them.</p>
  
  <p><strong>Background:</strong></p>
  
  <p>I understand that its looking for a primitive (i.e. guid), but I'm not sure how to work that into an effective <code>linq</code> statement.  I searched through <strong>SO</strong> and found many articles discussing a similar issue.  However, I either do not understand fully the problem or how those solutions can be interpreted correctly for my issue.</p>
  
  <p>This query worked fine when running in <code>VS 2013</code>.  The problem is only occurring in <code>VS 2015</code>.  I'm using <strong>.Net framework 4</strong> and <strong>Entity Framework 5</strong> (version 4.4).  I was using a license of <code>ReSharper</code>, but have since turned it off.  I'm not sure if I'm missing a configuration or not synching up correctly.  I've of course looked and all seems to be fine...not sure why <code>visual studio 2015</code> is acting up?</p>
  
  <p>I've also recreated the workspace and rebuilt with <code>VS 2015</code> just to make sure that <code>VS 2013</code> wasn't caching something somewhere.</p>
  
  <p><strong>Trials</strong></p>
  
  <p>I've simplified the problem to only 2 tables and the following query gives me this error also:</p>
  
  <pre><code>var tmp2 = from t in ctx.L_FORMS_SELECTION
             where ctx.L_FORMS_SEL_APPLICANT.Any(c =&gt; (c.form_id == t.form_id))
             select t;
  if ((tmp2.FirstOrDefault() != null))
      return true;
  </code></pre>
  
  <p>After some more simplification I ended up with a working query.  This one contains the two tables above plus a third one for illustration:</p>
  
  <pre><code>var tmp3 = from frmSel in ctx.L_FORMS_SELECTION
             join frmApp in ctx.L_FORMS_SEL_APPLICANT on frmSel.form_id equals frmApp.form_id
             join ins in ctx.L_FORMS_SEL_APP_INSIDER on frmSel.form_id equals ins.form_id
             select t3;
  if ((tmp3.FirstOrDefault() != null))
      return true;
  </code></pre>
  
  <p>So this is better, but I need to combine 20 tables...not just 3.  I could do a lot of joins but wouldn't this approach be less efficient and create more overhead?  Also, I'm still not sure why the original query works in <code>VS 2013</code> but not <code>VS 2015</code> - maybe I just need to focus on that and not spend effort on refactoring the query?</p>
  
  <p>Since the query didn't blow up, I expanded on it and just recreated my original query but this time using the 'join' keyword:</p>
  
  <pre><code>var tmp4 = from t in ctx.L_FORMS_SELECTION
             join app in ctx.L_FORMS_SEL_APPLICANT on t.form_id equals app.form_id
             join appState in ctx.L_FORMS_SEL_APP_STATE on t.form_id equals appState.form_id
             join appSource in ctx.L_FORMS_SEL_LOAN_APPSOURCE on t.form_id equals appSource.form_id
             join appMarital in ctx.L_FORMS_SEL_APP_MARITAL_STAT on t.form_id equals appMarital.form_id
             join appIns in ctx.L_FORMS_SEL_APP_INSIDER on t3.form_id equals appIns.form_id
             join prodCode in ctx.L_FORMS_SEL_PROD_CODE on t.form_id equals prodCode.form_id
             join prod in ctx.L_FORMS_SEL_PROD on t.form_id equals prod.form_id
             join queue in ctx.L_FORMS_SEL_QUEUE on t.form_id equals queue.form_id
             join coll in ctx.L_FORMS_SEL_COLLAT on t3.form_id equals coll.form_id
             join collState in ctx.L_FORMS_SEL_COLLAT_STATE on t.form_id equals collState.form_id
             join collView in ctx.L_FORMS_SEL_COLLAT_VIEW on t.form_id equals collView.form_id
             join collCnty in ctx.L_FORMS_SEL_COLLAT_COUNTY on t.form_id equals collCnty.form_id
             join loan in ctx.L_FORMS_SEL_LOAN on t.form_id equals loan.form_id
             join loanJur in ctx.L_FORMS_SEL_LOAN_JURISDICTION on t.form_id equals loanJur.form_id
             join loanPur in ctx.L_FORMS_SEL_LOAN_PURPOSE on t.form_id equals loanPur.form_id
             join reg in ctx.L_FORMS_SEL_REG on t.form_id equals reg.form_id
             join sub in ctx.L_FORMS_SEL_SUBSTITUTE on t.form_id equals sub.form_id
             join credit in ctx.L_FORMS_SEL_CREDIT_INS on t.form_id equals credit.form_id
             join rate in ctx.L_FORMS_SEL_RATE on t.form_id equals rate.form_id
             where t.shared_service_ind.ToUpper().Trim() == "E"
             select t;
  </code></pre>
  
  <p>This one doesn't throw an error...but does not return any value either (in VS 2013).  The original linq query returned a value (at least when I ran it in VS 2013) - strange.</p>
  
  <p>I looked at the results of the original query (run in VS2013) and found that there is a matching form_id.  I then ran a foreach query and got a match of course.  It seems that for some reason my 'equal' is not working correctly - maybe this is because form_id is a Guid.</p>
  
  <p>After more development...this is where I stand.  This query just loops through and exits the loop immediately after a value is found.  Thus I think this is more efficient, but also a little wordy and not as neat as I would like:</p>
  
  <pre><code>foreach (var rec in ctx.L_FORMS_SELECTION)
  {
      var app = ctx.L_FORMS_SEL_APPLICANT.Where(c =&gt; c.form_id == rec.form_id);
       if (app.FirstOrDefault() != null) return true;
  
       var appState = ctx.L_FORMS_SEL_APP_STATE.Where(c =&gt; c.form_id == rec.form_id);
       if (appState.FirstOrDefault() != null) return true;
  
       var appSource = ctx.L_FORMS_SEL_LOAN_APPSOURCE.Where(c =&gt; c.form_id == rec.form_id);
       if (appSource.FirstOrDefault() != null) return true;
  
       var appMarital = ctx.L_FORMS_SEL_APP_MARITAL_STAT.Where(c =&gt; c.form_id == rec.form_id);
       if (appMarital.FirstOrDefault() != null) return true;
  
       var appIns = ctx.L_FORMS_SEL_APP_INSIDER.Where(c =&gt; c.form_id == rec.form_id);
       if (appIns.FirstOrDefault() != null) return true;
  
       var prodCode = ctx.L_FORMS_SEL_PROD_CODE.Where(c =&gt; c.form_id == rec.form_id);
       if (prodCode.FirstOrDefault() != null) return true;
  
       var prod = ctx.L_FORMS_SEL_PROD.Where(c =&gt; c.form_id == rec.form_id);
       if (prod.FirstOrDefault() != null) return true;
  
       var queue = ctx.L_FORMS_SEL_QUEUE.Where(c =&gt; c.form_id == rec.form_id);
       if (queue.FirstOrDefault() != null) return true;
  
       var coll = ctx.L_FORMS_SEL_COLLAT.Where(c =&gt; c.form_id == rec.form_id);
       if (coll.FirstOrDefault() != null) return true;
  
       var collState = ctx.L_FORMS_SEL_COLLAT_STATE.Where(c =&gt; c.form_id == rec.form_id);
       if (collState.FirstOrDefault() != null) return true;
  
       var collView = ctx.L_FORMS_SEL_COLLAT_VIEW.Where(c =&gt; c.form_id == rec.form_id);
       if (collView.FirstOrDefault() != null) return true;
  
       var collCnty = ctx.L_FORMS_SEL_COLLAT_COUNTY.Where(c =&gt; c.form_id == rec.form_id);
       if (collCnty.FirstOrDefault() != null) return true;
  
       var loan = ctx.L_FORMS_SEL_LOAN.Where(c =&gt; c.form_id == rec.form_id);
       if (loan.FirstOrDefault() != null) return true;
  
       var loanJur = ctx.L_FORMS_SEL_LOAN_JURISDICTION.Where(c =&gt; c.form_id == rec.form_id);
       if (loanJur.FirstOrDefault() != null) return true;
  
       var loanPur = ctx.L_FORMS_SEL_LOAN_PURPOSE.Where(c =&gt; c.form_id == rec.form_id);
       if (loanPur.FirstOrDefault() != null) return true;
  
       var reg = ctx.L_FORMS_SEL_REG.Where(c =&gt; c.form_id == rec.form_id);
       if (reg.FirstOrDefault() != null) return true;
  
       var sub = ctx.L_FORMS_SEL_SUBSTITUTE.Where(c =&gt; c.form_id == rec.form_id);
       if (sub.FirstOrDefault() != null) return true;
  
       var credit = ctx.L_FORMS_SEL_CREDIT_INS.Where(c =&gt; c.form_id == rec.form_id);
       if (credit.FirstOrDefault() != null) return true;
  
       var rate = ctx.L_FORMS_SEL_RATE.Where(c =&gt; c.form_id == rec.form_id);
       if (rate.FirstOrDefault() != null) return true;
  }
  </code></pre>
  
  <p>Not sure if this can be done more consicely or not - its more code than the original.  I hope that this is all that VS 2015 doesn't like =)
  Thank you for reading through this and I appreciate any guidance provided.</p>