Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to create a constant value - only primitive types or Enumeration types allowed
    primarykey
    data
    text
    <p>I have seen some questions related to this Exception here but none made me understand the root cause of the problem. So here we have one more...</p> <pre><code>var testquery = ((from le in context.LoanEMIs.Include("LoanPmnt") join lp in context.LoanPmnts on le.Id equals lp.LoanEMIId where lp.PmntDtTm &lt; date &amp;&amp; lp.IsPaid == false &amp;&amp; le.IsActive == true &amp;&amp; lp.Amount &gt; 0 select new ObjGetAllPendingPmntDetails { Id = lp.Id, Table = "LoanEMI", loanEMIId = lp.LoanEMIId, Name = le.AcHead, Ref = SqlFunctions.StringConvert((double)le.FreqId), PmntDtTm = lp.PmntDtTm, Amount = lp.Amount, IsDiscard = lp.IsDiscarded, DiscardRemarks = lp.DiscardRemarks }).DefaultIfEmpty(ObjNull)); List&lt;ObjGetAllPendingPmntDetails&gt; test = testquery.ToList(); </code></pre> <p>This query gives the following Exception Message - </p> <blockquote> <p>Unable to create a constant value of type <code>CashVitae.ObjGetAllPendingPmntDetails</code>. Only primitive types or enumeration types are supported in this context.</p> </blockquote> <p>I got this Exception after I added the SQL function statement to convert <code>le.FreqId</code> which is a <code>byte</code> to a <code>string</code> as <code>ToString()</code> is not recognized in the LINQ Expression Store.</p> <p><code>ObjGetAllPendingPmntDetails</code> is a partial class in my model which is added as it is used too many times in the code to bind data to tables. It has both <code>ID</code>s as long, 'Amount' as decimal, <code>PmntDtTm</code> as <code>Datetime</code>,<code>IsDiscard</code> as bool and remaining all are string including 'Ref'.</p> <p>I get no results as currently no data satisfies the condition. While trying to handle null, I added <code>DefaultIfEmpty(ObjNull)</code> and <code>ObjNull</code> has all properties initialized as follows.</p> <pre><code>ObjGetAllPendingPmntDetails ObjNull = new ObjGetAllPendingPmntDetails() { Id = 0, Table = "-", loanEMIId = 0, Name = "-", Ref = "-", PmntDtTm = Convert.ToDateTime("01-01-1900"), Amount = 0, IsDiscard = false, DiscardRemarks = "" }; </code></pre> <p>I need this query to work fine as it has <code>Union()</code> called on it with 5 other queries. All returning the same <code>ObjGetAllPendingPmntDetails</code> columns. But there is some problem as this query has no data satisfying the conditions and the Exception Shared Above. </p> <p>Any suggestions are appreciated as I am unable to understand the root cause of the problem.</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.
 

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