C# 如何使用query获取今日&x27;约会活动

C# 如何使用query获取今日&x27;约会活动,c#,sql-server,entity-framework,linq,C#,Sql Server,Entity Framework,Linq,我用了这个,但是因为一个原因它不起作用,它在页面上什么也没有显示 TodayCheckedStatus = (from checkinout in context.Checkinout join status in context.Status on checkinout.CheckType equals status.Statusid where checkinout.Userid == use

我用了这个,但是因为一个原因它不起作用,它在页面上什么也没有显示

  TodayCheckedStatus = (from checkinout in context.Checkinout
                        join status in context.Status on checkinout.CheckType equals status.Statusid
                        where checkinout.Userid == userinfo.Userid
                        where checkinout.CheckTime == DateTime.Today.Date       
                        orderby checkinout.CheckTime descending
                        select new Checkinout
                        {
                         CheckStatus = status.StatusText,
                         CheckTime = checkinout.CheckTime
                         }).ToList()

在回答中重申@ikerbera的回应,所需的更改是

          where checkinout.CheckTime == DateTime.Today.Date 

什么类型是checkinout.CheckTime?它是日期时间类型吗?如果是DateTime类型,它在DateTime的时间部分是否有一些值?是的,它是DateTime类型,是的,它有时间值,但我只需要日期是今天的日期这是LINQ到EF(可能),而不是SQL。您使用的是哪个版本?在SQL中,您可以编写
WHERE cast(CheckTime as date)=@date
,其中
@date
是类型为
date
的参数,而不是
datetime
。不同的EF版本有不同的调用SQL函数的方法,尽管在处理ORM时不应该像这样使用连接。ORM的工作是从实体之间的关系生成连接。您也不需要多个
where
语句。结果相当于
@E.Lahu您应该这样做
,其中checkinout.CheckTime.Date==DateTime.Today.Date
where checkinout.CheckTime.Date == DateTime.Today.Date