Linq到sql c#Lamba传入日期
我希望能够传入日期Linq到sql c#Lamba传入日期,sql,linq,datetime,linq-to-sql,linq-to-entities,Sql,Linq,Datetime,Linq To Sql,Linq To Entities,我希望能够传入日期mm dd yyyy(2017年2月17日),因为sql server日期时间适用于此 所以我编写了一个lambda-linq-to-sql查询,但我一直在努力解决语法问题 var query = QALists //.Where (z => z.Disposition == "Verified") //.Where (z => z.CallDate == DateTime.ParseExact("20170215","MMddyyyy",Syste
mm dd yyyy
(2017年2月17日),因为sql server日期时间适用于此
所以我编写了一个lambda-linq-to-sql查询,但我一直在努力解决语法问题
var query = QALists
//.Where (z => z.Disposition == "Verified")
//.Where (z => z.CallDate == DateTime.ParseExact("20170215","MMddyyyy",System.Globalization.CultureInfo.InvariantCulture))
//.Where(z => Convert.ToDateTime(20170215, System.Globalization.CultureInfo.InvariantCulture))
.Where (z => DateTime.Parse(string.Format("{0}", z.Calldate.ToString() == "2-17-2017")))
.AsEnumerable()
.Select(z => new QAList()
{
Agent = z.Agent,
ClientName = z.ClientName,
Disposition = z.Disposition,
CallDate = z.Calldate,
Comment = z.Comment,
CreatedDateTime = z.CreatedDateTime,
CallLength = z.CallLength,
IdentityColumnId = z.IdentityColumnId,
Number = z.Number,
InboundCall = z.InboundCall,
OutboundCall = z.OutboundCall,
Status = z.Status,
QAListId = z.QAListId
}).ToList();
我在sql server上用c注释了我的各种测试CallDate
看起来像2017-02-09T07:51:00.76
如何使用.Where lambda简单地解析传入日期
CallDate在poco中看起来像此属性
public DateTime CallDate { get; set; }
只需使用构造函数创建日期,并使用date属性DateTime
.Where (z => z.Calldate.Date == new DateTime(2017,2,17).Date)
ArgumentOutOfRangeException:Year、Month和Day参数描述了一个不可表示的日期时间。@JeremyMiller——你真的不知道如何交换2和17吗?无论如何,我编辑过它。