简体   繁体   English

如何在linq中写入查询以获取最近3个月的记录到sql?

[英]How write query for getting last 3 months records in linq to sql?

I want to display last 3 months sales records.Based on current month will show it's previous records in linq to sql.Please tell me the query for that. 我想显示最近3个月的销售记录。基于当前月份将显示它以前在linq中的记录到sql。请告诉我查询。

If current month is june then will show apr,may,june records. 如果当前月份是6月那么将显示apr,may,june记录。

id name  no.ofsales  desc          datevalue
1  test    12        test desc     2013-10-12 
2  test1   16        desc message  2013-09-14

Give me idea on this query. 给我这个查询的想法。

I think something like this could work: 我觉得这样的事情可以奏效:

yourCollection.Where(x => 
    DateTime.Compare(x.DateTimeProperty, DateTime.Today.AddMonths(-3)) >= 0);
var minDate = DateTime.Now.AddMonths(-3);

from x in datatable
where x.datevalue> minDate
select x;
from x in datatable
where x.datevalue> DateTime.Now.AddMonths(-3) 
orderby x.id ascending
select x;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM