我想一個DateTime值轉換爲字符串,但我得到這個運行時錯誤轉換:在LINQ表達式中使用的ToString()來DateTime值
Additional information: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
這是我的查詢使用:
using (var db = new DbContext())
{
var results = (from u in db.AspNetUserses
join upi in db.UserPersonalInfoes on u.Id equals upi.UserId into upis
from upi in upis.DefaultIfEmpty()
join up in db.UserPreferenceses on u.Id equals up.UserId into ups
from up in ups.DefaultIfEmpty()
join us in db.UserStatses on u.Id equals us.UserId into uss
from us in uss.DefaultIfEmpty()
select new
{
Username = u.UserName,
Telephone = (upi == null ? String.Empty : upi.Telephone),
ID = u.Id,
LastLogin = (us == null ? String.Empty : us.LastLoginDate)
}).ToList();
gvUsers.DataSource = results;
gvUsers.DataBind();
}
任何想法如何解決這個錯誤?
嗯,在那個代碼中你將'DateTime'轉換爲'string'?你的意思是寫'us.LastLoginDate.ToString()'? – 2015-01-20 19:57:43
是的,多數民衆贊成我所嘗試的,對不起 – Laziale 2015-01-20 20:00:34