[英]How can I write the “Where” clause in the following LINQ to SQL Query?
[英]How can I write this query in linq to sql?
我是linq的新手,想编写以下查询:
var query = from p in behzad.rptost
where p.date.substring(0, 4) == "1395"
-->in this calc sum=p.price_moavaq+price_year
select p;
如何编写该查询?
根据我的假设,您正在尝试总结每年的price_moavaq
字段。 此外,通过使用substring
我猜您的date
字段不是DateTime
类型,而只是string
。
因此,您需要使用groupby
:
var query = from p in behzad.rptost
group p by p.date.substring(0, 4) into grouping
select new { Year = p.Key, Sum = p.Sum(x => x.price_moavaq);
如果您的日期字段为DateTime
类型,则只需使用.Year
:
var query = from p in behzad.rptost
group p by p.date.Year into grouping
select new { Year = p.Key, Sum = p.Sum(x => x.price_moavaq);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.