0

请让我知道我将如何从中进行 Linq 查询。

SELECT 
[GroupBy1].[K1] AS [AccountName], 

[GroupBy1].[K2] AS [LeadBy], 

[GroupBy1].[K3] AS [Status], 

[GroupBy1].[K3] AS [Industry], 

[GroupBy1].[A1] AS [C2]

FROM ( SELECT 
    [Extent1].[AccountName] AS [K1],

     [Extent2].[LeadBY] AS [K2],

     [Extent2].[Status] AS [K3],

     [Extent2].[Industry] AS [K4],

    COUNT(1) AS [A1]

    FROM [dbo].[Opportunities] AS [Extent1]

    join [dbo].[Leads] AS [Extent2]

    on [Extent1].[AccountName] IS NOT NULL

    AND [Extent1].[AccountName]=[Extent2].[AccountName]

    GROUP BY [Extent1].[AccountName],[Extent2].[Leadby],[Extent2].[Status],[Extent2].
[Industry]
)  AS [GroupBy1]
4

2 回答 2

0

它取决于您的映射,如果您没有外键进入 AccountName 列,您应该尝试以下操作:

from i in Context.Opportunities
join l in Context.Leads on l.AccountName equals i.AccountName
group i by new { i.AccountName, l.LeadBY, l.Status, l.Industry } into g
select new
{
    g.Key.AccountName,
    g.Key.LeadBY,
    g.Key.Status,
    g.Key.Industry,
    Count = g.Count();
}

如果你有一个外键可以进入 AccountName 列,你应该试试这个:

from i in Context.Opportunities
group i by new { i.AccountName, l.Lead.LeadBY, l.Lead.Status, l.Lead.Industry } into g
select new
{
    g.Key.AccountName,
    g.Key.LeadBY,
    g.Key.Status,
    g.Key.Industry,
    Count = g.Count();
}
于 2012-12-13T17:01:18.050 回答
0

尝试使用这个程序: http ://www.linqpad.net/它有基本和高级操作的例子。您也可以下载其他教程。

于 2012-12-13T04:47:54.583 回答