0

如何进行 linq 查询以获取过去 2 年的记录。现在的主要问题是数据网格加载到许多记录并且速度变慢,所以我试图通过获取过去 2 年的记录来减少这个数量。我已经搜索过,但似乎不知道我可以使用或应该使用什么。我记得在 Mysql 中做过,但我似乎在 Linq 中找不到这些选项。我很确定 linq 也可以,但我不知道怎么做。

那么有人可以帮我解决这个问题吗?

 dim getRecord = (From rec in DB.table
                 Where rec.date ....  ' no idea
                 Select rec.date).ToList()
4

2 回答 2

4

你可以尝试类似的东西

Where rec.date > DateTime.Now.AddYears(-2)

如果您有大量记录,请不要忘记在日期列上添加索引

于 2012-09-11T12:50:01.980 回答
1
Dim twoYearsAgo = DateTime.Now.AddYears(-2);
dim getRecord = (From rec in DB.table 
                 Where rec.date >= twoYearsAgo
                 Select rec.date).ToList() 
于 2012-09-11T12:49:17.667 回答