gpt4 book ai didi

c# - 无法在 linq 查询中将类型字符串转换为十进制

转载 作者:行者123 更新时间:2023-11-30 17:44:40 26 4
gpt4 key购买 nike

我有我的 linq 查询,我要在其中加入 3 个表。将它们分组,这样我就可以对表 3 中的值求和

var roles = from p in db.Properties 
join od in db.tblOrderDetails on p.pID equals od.odpID
join s in db.tblServices on od.odsID equals s.sID
where p.poID == 0 && p.pActive == true

group s by new {p.pID, p.pAddress} into g
select new
{
ID = g.Key.pID,
Address = g.Key.pAddress,
SubTotal = g.Sum(s => s.sPrice)
};

我的问题出在小计上。我收到“无法将类型‘字符串’隐式转换为‘十进制?’”我尝试使用 convert.todecimal 但我得到了

LINQ to Entities does not recognize the method 'System.Decimal ToDecimal(System.String)' method, and this method cannot be translated into a store expression.

sqlfunctions.stringconvert 也没有帮助。有什么想法吗?

最佳答案

我认为如果数据量相当小,可以使用从 LINQ to Entities 到 LINQ to Objects 的这种转换:

  var roles = (from p in db.Properties 
join od in db.tblOrderDetails on p.pID equals od.odpID
join s in db.tblServices on od.odsID equals s.sID
where p.poID == 0 && p.pActive == true

group s by new {p.pID, p.pAddress} into g)
.AsEnumerable().Select(p => new
{
ID = p.Key.pID,
Address = p.Key.pAddress,
SubTotal = p.Sum(s => s.sPrice)
});

关于c# - 无法在 linq 查询中将类型字符串转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29169835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com