亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

LINQ to Entities異常不支持指定的類型成員'Date'

LINQ to Entities異常不支持指定的類型成員'Date'

ibeautiful 2019-11-12 10:15:44
在執行以下語句時出現異常。 DateTime result; if (!DateTime.TryParse(rule.data, out result))     return jobdescriptions; if (result < new DateTime(1754, 1, 1)) // sql can't handle dates before 1-1-1753     return jobdescriptions; return jobdescriptions.Where(j => j.JobDeadline.Date == Convert.ToDateTime(rule.data).Date );例外The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.我知道例外的含義,但我不知道如何擺脫它。有什么幫助嗎?
查看完整描述

3 回答

?
長風秋雁

TA貢獻1757條經驗 獲得超7個贊

您可以使用EntityFunctions的TruncateTime方法將屬性正確轉換為SQL:Date


using System.Data.Objects; // you need this namespace for EntityFunctions


// ...


DateTime ruleData = Convert.ToDateTime(rule.data).Date;

return jobdescriptions

    .Where(j => EntityFunctions.TruncateTime(j.JobDeadline) == ruleData);


更新: EntityFunctions在EF6中已棄用,使用DbFunctions.TruncateTime


查看完整回答
反對 回復 2019-11-12
  • 3 回答
  • 0 關注
  • 1540 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號