Note that there are some explanatory texts on larger screens.

plurals
  1. POInt.Parse in Linq Expression
    primarykey
    data
    text
    <p>I have following linq expression. I want calculate sum of numeric values in Nvarchar field. I use following code to do this. But I get an error when I try to run this.</p> <pre><code> var m = new MaterialModelContainer(); var list = (from x in ( from inv in m.INVs join l in m.LIBs on inv.MESC equals l.MESC join o in m.OUTs on inv.MESC equals o.MESC join t in m.TRANs on inv.MESC equals t.MESC where t.TYPE == "60" select new { l.MESC, l.LINE_NO, l.UNIT_LINE, Description = l.DES + " " + l.PART_NO, inv.NEW_QTY, o.PJ, o.DATE, o.QTY, o.QTY_REC, TranQty = t.QTY, tranDate = t.DATE } ) group x by new { x.MESC, x.LINE_NO, x.UNIT_LINE, x.Description, x.NEW_QTY, x.PJ, x.DATE, x.QTY, x.QTY_REC } into g select new { QTY_Consum_1 = g.Where(c =&gt; int.Parse(c.tranDate) &gt;= cuDate &amp;&amp; int.Parse(c.tranDate) &lt;= endDate).Sum(d =&gt; int.Parse(d.TranQty)) } ).ToList(); </code></pre> <p><strong>Error Description:</strong><br></p> <blockquote> <p>LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression <br></p> </blockquote> <p>How can i solve this problem and write this code better than this?</p> <p>i change code to this</p> <pre><code> select new { QTY_Consum_1 = g.Where(c =&gt; SqlFunctions.StringConvert(c.tranDate) &gt;= cuDate &amp;&amp; SqlFunctions.StringConvert(c.tranDate) &lt;= endDate).Sum(d =&gt; SqlFunctions.StringConvert(d.TranQty)), g.Key.MESC } ).ToList(); </code></pre> <p>but get this error <img src="https://i.stack.imgur.com/hJQjN.jpg" alt="enter image description here"></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