Int.Parse en Expresión Linq
Tengo la siguiente expresión de linq. Quiero calcular la suma de los valores numéricos en el campo Nvarchar. Yo uso el siguiente código para hacer esto. Pero me sale un error cuando intento ejecutar esto.
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 => int.Parse(c.tranDate) >= cuDate && int.Parse(c.tranDate) <= endDate).Sum(d => int.Parse(d.TranQty))
}
).ToList();
Error de descripción:
LINQ to Entities no reconoce el método 'Int32 Parse (System.String)', y este método no se puede traducir a una expresión de tienda
¿Cómo puedo resolver este problema y escribir este código mejor que esto?
cambio el código a esto
select new
{
QTY_Consum_1 = g.Where(c => SqlFunctions.StringConvert(c.tranDate) >= cuDate && SqlFunctions.StringConvert(c.tranDate) <= endDate).Sum(d => SqlFunctions.StringConvert(d.TranQty)),
g.Key.MESC
}
).ToList();
pero recibe este error