我想獲取用戶的最後登錄日期,如果沒有登錄記錄存在,返回今天的日期。我需要一些幫助到達那裏。我收到以下錯誤,甚至沒有默認值組件。Linq Max與默認值
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.DateTime?'
DateTime? logdate = from userlog in
(from userlog in db.UserLogEntities
where
userlog.UserID == 1 &&
userlog.Action == "Logon" &&
userlog.ActionTag == "Success"
select new
{
userlog.LogDate,
Dummy = "x"
})
group userlog by new { userlog.Dummy } into g
select new
{
Column1 = (DateTime?)g.Max(p => p.LogDate)
};
另一種選擇:... select(DateTime?)ul.LogDate).DefaultIfEmpty()。Max() – Hans 2013-02-12 00:27:09