的常量值我收到以下錯誤: 異常詳細信息:System.NotSupportedException:無法創建類型爲'FileCombined'的常量值。只有原始類型或枚舉類型在此背景下Linq With Entity Framework錯誤 - 無法創建類型
我使用下面的代碼的支持:
var o1 = new FileCombined(){ ScholarshipID = 3, FileDescription = "smt" };
var o2 = new FileCombined() { ScholarshipID = 10, FileDescription = "smt" };
List <FileCombined> list = new FileCombined[] { o1, o2 }.ToList();
var data = (from scholarship in db.ScholarshipRequests
join file in list on scholarship.ScholarshipRequestID equals file.ScholarshipID
select new { ScholarshipID = scholarship.ScholarshipRequestID, FileDescription = file.FileDescription }).ToList();
如果我改變了LINQ表達的順序,查詢工作正常:
var o1 = new FileCombined(){ ScholarshipID = 3, FileDescription = "smt" };
var o2 = new FileCombined() { ScholarshipID = 10, FileDescription = "smt" };
List <FileCombined> list = new FileCombined[] { o1, o2 }.ToList();
var data = (from file in list
join scholarship in db.ScholarshipRequests on file.ScholarshipID equals scholarship.ScholarshipRequestID
select new FileCombined(){ ScholarshipID = scholarship.ScholarshipRequestID, FileDescription = file.FileDescription }).ToList();
任何人都可以解釋或找到解決方案? 我需要先查詢工作,因爲我在不斷的代碼
連接到數據庫ScholarshipRequests?如果它在第一個代碼示例中,LINQ將嘗試在不知道List對象的DB上運行查詢。 –
感謝您的解釋。 – kfir