我尝试将该SQL查询转换为链接,但它不起作用。
SELECT
SUM([Quantity]) as qt
,[ArticleID]
FROM [DB].[dbo].[Location]
Group by ArticleID
Order by qt
List <Location> articles = contexteEF.Location.GroupBy(l => l.ArticleID).Select(a => new { qt = a.Sum(b => b.Quantity), ArticleID = a.Key }).OrderByDescending(a => a.qt).ToList();
你能帮帮我吗?请!
由于
答案 0 :(得分:0)
您正在尝试将动态对象列表转换为List<Location>
我认为该位置包含qt
和ArticleId
属性?在这种情况下,不要创建动态对象,创建位置。代码未经过测试,但有类似的内容:
List <Location> articles = contexteEF.Location.GroupBy(l => l.ArticleID).Select(a => new Location() { qt = a.Sum(b => b.Quantity), ArticleID = a.Key }).OrderByDescending(a => a.qt).ToList();