如何仅比较DateTime对象的时间而没有获得以下内容

错误:

An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code Additional information: The specified type member 'TimeOfDay' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

我的代码:
var date = DateTime.Parse(query.DueTime);
entities = entities.Where(r => r.DueTime.TimeOfDay.Equals(date.TimeOfDay));

最佳答案

这就是答案!

var date = DateTime.Parse(query.DueTime);
var time = date.TimeOfDay;
entities = entities.Where(r => DbFunctions.CreateTime(r.DueTime.Hour, r.DueTime.Minute,  r.DueTime.Second) == time);

10-01 12:19