【发布时间】:2018-06-10 20:50:23
【问题描述】:
这里的想法是将所有食谱中的所有成分加起来。这是我的查询
SELECT IngredientName,sum(Amount) as Amount,Unit
FROM RecipeIngredients Join Ingredients ON RecipeIngredients.IngredientID = Ingredients.IngredientsID
GROUP BY IngredientID,IngredientName,Unit
ORDER BY IngredientName
效果很好。没有问题。我对 linq to sql 语法感到困惑。 这是我目前所拥有的。
using (lDataContext db = new lDataContext())
{
return (from ri in db.RecipeIngredients join i in db.Ingredients on ri.IngredientID equals i.IngredientsID
group new {ri,i} by new {i.IngredientsID,i.IngredientName,ri.Unit }
into table
select new {
Name = table.IngredientName
Unit = table.Unit
Amount = table.Sum(i.amount) }
).ToList();
}
有人可以帮我解决一下我的语法吗?
【问题讨论】:
-
您是否通过示例查找分组并阅读文档?相信我,这很简单,您可以通过查找这些内容了解更多信息
-
文档在哪里?
-
来吧,这里有例子搜索功能,文档有谷歌。
标签: c# asp.net sql-server linq