I need to convert that SQL Query into Linq:
SELECT
SUM([ArticleAmount]) as amount
,[ArticleName]
FROM [DB].[dbo].[OrderedArticle]
group by articlename
You are getting this error because the Grouping doesn't return IEnumerable<OrderedArticle>
but IEnumerable<IGrouping<string, OrderedArticle>>
You need to change your code to use a.Key
:
var sells = orderedArt
.GroupBy(a => a.ArticleName)
.Select(a => new { Amount = a.Sum(b => b.ArticleAmount), Name = a.Key})
.OrderByDescending(a => a.Amount)
.ToList();