我收到以下错误:异常详细信息:System.NotSupportedException:无法创建“FileCombined”类型的常量值。此上下文仅支持原始类型或枚举类型
我正在使用以下代码:
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();
谁能解释或找到解决方案?我需要第一个查询才能工作,因为我在连续代码中有更复杂的查询