使用Linq to SQL在一个查询中使用多个聚合函数

时间:2017-07-17 12:13:19

标签: c# entity-framework linq aggregate-functions

我试图在LINQ(EF6)中实现以下功能:

var dbCofing = {
    user: 'USER',
    password: 'PASS',
    server: '53.165.137.28',
    instanceName: 'NAME',
    port: 94273,
    database: 'DATABASE'
}

C#代码如下所示:

SELECT character.firstname AS femaleFName, character.lastname AS femaleLName
FROM Couple INNER JOIN Character ON Character.characterID = Couple.femaleID

如何在不同的字段上应用多个聚合函数?具体来说,在某种程度上,不会导致在结果查询中反复复制复杂的条件?

1 个答案:

答案 0 :(得分:6)

您可以通过常量技巧使用组来获取具有单个SQL查询的所有聚合(以及共享的复杂过滤器):

x_list = [item for sub in A_list[::2] for item in sub]
y_list = [item for sub in A_list[1::2] for item in sub]