Ahm*_*mad 0 c# sql entity-framework iqueryable entity-framework-6
我有一个表,我想在实体框架工作中执行以下操作:
1-从对象返回一些列而不是所有列(我为这个新类型创建了新类,只包含我需要的列,并在select语句中返回其中的值.
2-返回列应按某些列分组,其中两列将包含计数值.(这是我的问题).
有关更多说明:我需要在Entity Framework中对我的数据集的可共享对象映射以下查询:
select SUM (Col1) SUM_Col1, SUM (Col2) SUM_Col2, COUNT (*) RECORDS, Col3, Col4, Col5
from myTable
where col3 = 'some value'
group by Col3, Col4, Col5;
Run Code Online (Sandbox Code Playgroud)
我的分组审判如下:
query = from record in context.tables
group record by new
{
record.Col3,
record.Col4,
record.Col5,
} into g
select new QueryResult
{
Col1 = (need Sum of Col1 here),
Col2 = (need Sumn of Col2 here),
Col3 = g.Key.Col3,
Col4 = g.Key.Col4,
Col5 = g.Key.Col5,
Col6 = ( need count of grouped records here)
};
Run Code Online (Sandbox Code Playgroud)
query = from record in context.tables
group record by new
{
record.Col3,
record.Col4,
record.Col5,
} into g
select new QueryResult
{
Col1 = g.Sum(x => x.Col1),
Col2 = g.Sum(x => x.Col2),
Col3 = g.Key.Col3,
Col4 = g.Key.Col4,
Col5 = g.Key.Col5,
col6 = g.Count()
};
Run Code Online (Sandbox Code Playgroud)