2
(from sms in db.sms
                where sms.NeedModeration == true && sms.ReplyStatus == "test" && **sms.date.Value == date**
                select new 
                 {
                     SMSID = sms.SmsID,
                     Body = sms.body,
                     Date=sms.date,
                     ReplyStatus = sms.ReplyStatus
                 }).AsEnumerable().Select(x=>new VMSMS{
                     SMSID=x.SMSID,
                     Body=x.Body,
                     Date= x.Date.Value,
                     ReplyStatus = x.ReplyStatus
                 })

给定的代码可以正常工作,但是在哪里我只想匹配 DATETIME 类型的日期部分,例如

 sms.date.Value.Date == date.Date

但它不能正常工作它向我显示以下错误

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

那么你能告诉我如何从LINQ 中的 DateTime类型中提取 Date 部分吗?

这是短信 ViewModel 代码....

public class VMSMS
{
    public long SMSID { get; set; }
    public string SMS { get; set; }
    public int? SPOID { get; set; }
    public string Body { get; set; }
    public string EmployeeName { get; set; }
    [IgnoreDataMember]
    public DateTime Date { get; set; }        
    public bool? IsRead { get; set; }
    public string DoctorCode { get; set; }
    public string ReplyStatus { get; set; }
}
4

2 回答 2

0

感谢大家的帮助。最后我得到了答案,应该这样做

EntityFunctions.TruncateTime(sms.date.Value) == EntityFunctions.TruncateTime(date)

它将从日期时间截断时间。

于 2012-10-12T05:51:18.973 回答
0

因为您在 Date 属性上有 IgnoreDataMember,所以它不会映射到您的模型中。

因此,完成投影后,您的比较需要在 Linq-to-Object 级别进行。

于 2012-10-11T11:54:38.050 回答