你好,
根据你的描述,我写了一个简单的Demo, 是可以返回满足条件的记录的。我使用的Entity framework 6.1.3 Code First, .Net framework 4.6.1.
你可以提供一个简单的,可以重现你问题的Demo, 然后上传到OneDrive, 把共享链接发到这里。
下面是我使用的例子,你可以参考一下。
数据库
CREATE TABLE [dbo].[tz_LaborCheckRecord] (
[Id] INT NOT NULL,
[InputDate] DATETIME NOT NULL,
[CheckDate] DATETIME NOT NULL,
[UID] VARCHAR (50) NULL,
[Account] VARCHAR (50) NULL
);
控制台代码.
using System;
using System.Data.Entity; //注意:要添加这个引用
using System.Linq;
namespace DatediffDemo
{
class Program
{
static void Main(string[] args)
{
using (var db = new EFDemoContext())
{
var localDB = (from l in db.tz_LaborCheckRecord
where (DbFunctions.DiffDays(l.InputDate, l.CheckDate) > 2) //去掉这句返回所有记录
select new ListForLaborCheckRecordLateVM
{
ID = l.Id,
UID = l.UID,
InputDate = l.InputDate,
CheckDateDate = l.CheckDate,
Account = l.Account,
}).ToList();
Console.ReadKey();
}
}
}
}
Best regards,
Zhanglong Wu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.