这里的想法是将所有配方中的所有成分加起来。这是我的查询
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();
}
请大家帮我解释一下我的语法?
答案 0 :(得分:0)
假设您没有使用LINQ to Entities而只使用LINQ to SQL,
将SQL转换为LINQ,