我有一个表,我想在实体框架中执行以下操作:
1-从对象返回一些列而不是所有列(我为这个新类型创建了新类,只包含我需要的列,并在select语句中返回值。
2-返回列应按某些列分组,其中两列将包含计数值。 (这是我的问题)。
有关更多说明:我需要在Entity Framework中对我的数据集的可共享对象映射以下查询:
paragraphs map { a =>
} filter { b =>
} map { c =>
} sortBy { d =>
}.reverse
我的分组审判如下:
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;
答案 0 :(得分:5)
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()
};
答案 1 :(得分:1)
尝试此查询:
if($("#pcheck").is(":checked") && $("#txt").val()=="1")
答案 2 :(得分:0)
也许这个例子可以帮助你,它将两列相加并与另一个表进行连接
from e in _context.LearnResults
join c in _context.Country on e.CountryId equals c.CountryId
where c.DomainId.Equals("xx")
group e by e.Country.Name into newCountry
let Approved = newCountry.Sum(e => e.Approved)
let Total = newCountry.Sum(e => e.Total)
select new LearnResults() { CountryName = newCountry.Key, Approved= Approved, Total=Total };