我一直在使用一些LINQ over Entities,我得到了奇怪的结果,我想得到解释......
给出以下LINQ查询,
// Sample # 1
IEnumerable<GroupInformation> groupingInfo;
groupingInfo = from a in context.AccountingTransaction
group a by a.Type into grp
select new GroupInformation()
{
GroupName = grp.Key,
GroupCount = grp.Count()
};
Run Code Online (Sandbox Code Playgroud)
我得到以下SQL查询(取自SQL Profiler):
SELECT
1 AS [C1],
[GroupBy1].[K1] AS [Type],
[GroupBy1].[A1] AS [C2]
FROM ( SELECT
[Extent1].[Type] AS [K1],
COUNT(1) AS [A1]
FROM [dbo].[AccountingTransaction] AS [Extent1]
GROUP BY [Extent1].[Type]
) AS [GroupBy1]
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
如果我将我的LINQ查询更改为:
// Sample # 2
groupingInfo = context.AccountingTransaction.
GroupBy(a => a.Type).
Select(grp => new GroupInformation() …Run Code Online (Sandbox Code Playgroud) c# linq entity-framework entity-framework-4 entity-framework-6