C# LINQ to实体仅支持强制转换EDM基元或枚举类型错误

C# LINQ to实体仅支持强制转换EDM基元或枚举类型错误,c#,linq,entity-framework,linq-to-entities,C#,Linq,Entity Framework,Linq To Entities,现在可能有几十个问题都有重复的标题,所以,如果这是重复的,我很抱歉,但是我与LINQ I的有限经验无法找到解决方案。我正在尝试检索最后一封邮件,FirstName和lastname,以及最后一封邮件的发送日期,按identNumber分组。sql查询工作正常,LINQ返回: Unable to cast the type 'System.Nullable`1' to type 'System.Object'. LINQ to Entities only supports casting EDM

现在可能有几十个问题都有重复的标题,所以,如果这是重复的,我很抱歉,但是我与LINQ I的有限经验无法找到解决方案。我正在尝试检索最后一封邮件,FirstName和lastname,以及最后一封邮件的发送日期,按identNumber分组。sql查询工作正常,LINQ返回:

Unable to cast the type 'System.Nullable`1' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types
显然有些东西是空的,但我不确定正确的翻译是什么

SQL:

SELECT     e.identNumber, e.DateSent, e.FirstName, e.LastName
FROM         Echo.vw_EchoChatMessages AS e,
  (SELECT MAX(DateSent) AS MaxDate, identNumber
  FROM Echo.vw_EchoChatMessages
  GROUP BY identNumber ) MaxResults
WHERE e.identNumber = MaxResults.identNumber
AND e.DateSent = MaxResults.MaxDate
LINQ(我能得到的最近的):


请尽可能地建议,thanx

EF无法识别编译器为
.Equals()
调用生成的从
Nullable
object
的隐式转换


将其更改为
=
运算符,您应该会没事,因为规范在
T
Nullable

之间定义了一个相等运算符,谢谢。这是一个巨大的帮助!我永远也想不到这一点。
                var qry = from c in db.vw_EchoChatMessages
                      let maxDate = (from d in db.vw_EchoChatMessages select d.DateSent).Max()
                      where c.DateSent.Equals(maxDate)
                      select new { c.FirstName, c.LastName, c.DateSent };