-3
Select查詢我從數據庫使用LINQ
[Serializable]
Public sealed class LayEntity : EntityBase
{
Public string Name {get;set;} // Getting mapped to the same column name in db table
}
在我的.cs稱爲實體類文件我有一個查詢爲:
LayEntity lay = null;
Using(var context = new DBContext())
{
lay = context.LayTable.where(x=>x.id >1).Select (y=>y.Name).FirstOrDefault();
}
我的目的是存儲檢索名稱提交的到實體類。 但我得到一個編譯時錯誤爲'不能隱式地將字符串轉換爲實體'。那我需要做什麼?
爲什麼不發佈代碼,至少編譯? – Dennis
你選擇'y => y.Name'這是一個'string',並嘗試將它分配給'lay',它是'LayEntity'。刪除'.Select(y => y.Name)',它會起作用。 –