我是一个新手学习LINQ。我在编码方面有一些问题。我使用 Convert.Int32 将列从字符串转换为整数。我的返回函数使用列表。因此,在我的代码中,我使用 foreach 将查询数据移动到 List,但是当我运行此代码时出现错误。并且错误总是在“foreach”上并带有错误消息:
LINQ to Entities 无法识别方法“Int32 ToInt32(System.String)”方法,并且该方法无法转换为存储表达式。
这是我的代码:
var query = from o in _invoiceRepository.Table
join opv in _opvRepository.Table on o.Id equals opv.InvoiceId
join pv in _pvRepository.Table on opv.ProductVariantId equals pv.Id
join p in _pRepository.Table on pv.ProductId equals p.Id
where !o.Deleted && EndDate >= o.CreatedOnUtc && StartDate <= o.CreatedOnUtc
&& opv.SubstitutedBy != null && o.PaidDateUtc != null
orderby o.GHOrderId, pv.Sku
select new
{
OrderId = o.GHOrderId,
SKU = pv.Sku,
Brand = p.BrandII,
Description = pv.Description,
Size = p.Size,
OrderQty = Convert.ToInt32(opv.OrderQuantity)
};
var query2 = from row in query
group row by new
{ row.OrderId, row.SKU, row.Brand, row.Description, row.Size } into result
select new
{
OrderId = result.Key.OrderId,
SKU = result.Key.SKU,
Brand = result.Key.Brand,
Description = result.Key.Description,
Size = result.Key.Size,
OrderQty = result.Sum(row => row.OrderQty).ToString("n2")
};
List<string> _tempdata = new List<string>();
foreach (var order in query.ToList())
{
_tempdata.Add(order.OrderId.ToString() + ';' + order.SKU.ToString() + ';' + order.Brand.ToString() + ';' + order.Description.ToString() + ';' + order.Size.ToString() + ';' + order.OrderQty.ToString());
}
我不知道如何解决这个问题......我需要你的帮助......
谢谢你。