【发布时间】:2011-10-15 22:14:56
【问题描述】:
需要重构的Linq-To-SQL如下:
var query = from p in Cache.Model.Products
join sc in Cache.Model.ShishaCombinations on p.ProductID equals sc.ProductID
where sc.NumberOfMixes == mixes
select new { p.ProductID, p.Name };
使用以下单行:
group by p.ProductID
我知道 group by 省略了对 select 子句的任何需求,因此两者可以一起存在于同一个 LINQ-To-SQL 语句中,所以有人可以帮我重构上述内容吗?
帮助我删除结果中的所有重复数据。
【问题讨论】:
-
真的不清楚你所说的“To-SQL found below refactoring”是什么意思。鉴于您需要 NumberOfMixes 属性,您不能仅分组。
-
(如果你能展示你想要得到的结果,这可能有助于你的问题更清楚。)
标签: c# linq entity-framework .net-4.0 group-by