Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq到sql c#Lamba传入日期_Sql_Linq_Datetime_Linq To Sql_Linq To Entities - Fatal编程技术网

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吗?无论如何,我编辑过它。