我怎么能用CreateDate在Date1var和amp;之间的where子句来写这个。 Date2var?

时间:2016-07-01 15:34:10

标签: c# linq

我怎样才能在其中CreatedDate介于Date1var&之间的where子句中写这个。 Date2var?

        return _context.Logs.Where(x => x.ApplicationID == applicationId)
            .OrderByDescending(x => x.ID)
            .Take(count)
            .Select(record => new LoggingLogic.entities.Log
            {
                DataL = record.Data,
                LogMessage = record.Message,
                CreatedDate = record.CreateDate,
                ApplicationName = record.Application.Name,
                Environment = record.Application.Environment.EnvironmentName,
                ID = record.ID
            });

2 个答案:

答案 0 :(得分:2)

将您的Where()更改为Where(x => x.ApplicationID = applicationId && x.CreatedDate >= Date1var && x.CreatedDate <= Date2var)

我假设您希望范围具有包容性。

答案 1 :(得分:1)

试试这个

return _context.Logs.Where(x => x.ApplicationID == applicationId && x.CreatedDate >= Date1Var && x.CreatedDate <= Date2Var)
            .OrderByDescending(x => x.ID)
            .Take(count)
            .Select(record => new LoggingLogic.entities.Log
            {
                DataL = record.Data,
                LogMessage = record.Message,
                CreatedDate = record.CreateDate,
                ApplicationName = record.Application.Name,
                Environment = record.Application.Environment.EnvironmentName,
                ID = record.ID
            });