2
我正在使用System.Linq.Dynamic作为需要用户选择在运行时选择/投影哪些属性的项目。动态Linq .Select() - 如何处理某些空值
所以,我有这样的查询:
var query = db.Users.Select("New(UserId, Username, Groups.Max(DateInserted) AS DateInserted)");
的DateInserted列不为空,但并不是所有的用户都组。 所以,当没有组返回一个用户,我得到以下错误:
"The cast to value type 'DateTime' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type."
有什么我可以在查询呢?我无法使列可以为空。
感谢您的任何帮助。
谢谢你的建议。当我尝试这样做时,我得到以下异常:“LINQ to Entities只支持无参数的构造函数和初始化器。” – 2012-11-20 18:07:21