我正在创建一个测验,其中包含以下课程
Quiz
具有属性CorrectOption
, WrongOption1
, WrongOption2
, WrongOption3
.
在其中DTO
我有List<String> Options
将包含所有错误和正确选项的内容。
在检索实体时,我正在使用 DTO 的对象初始化程序,但不知道如何分配 List<String> Options
。
我记得我们使用匿名方法来做到这一点。
select new QuestionDTO
{
Category = q.QuizCategory.Text
,
CorrectOption = q.CorrectOption
,
DifficultyLevel = q.DifficultyLevel.Text
,
Points = q.DifficultyLevel.Points.Value
,
RewardPCT = q.DifficultyLevel.RewardPCT.Value
,
Text = q.Text
,
TimerDuration = q.DifficultyLevel.TimerDuration.Value
,
Options = (qz) =>
{
List<string> ops = new List<string>();
ops.Add(q.CorrectOption);
ops.Add(q.WrongOption1);
ops.Add(q.WrongOption2);
ops.Add(q.WrongOption3);
return new List<string>().Shuffle();
}
};
但它给出了以下错误。
无法将 lambda 表达式转换为类型“System.Collections.Generic.List”,因为它不是委托类型。
更新
例如,我在原始实体类上创建了一个只读属性来完成这项工作。但请让我知道更好的方法。谢谢
更新2
但它没有用:p 在 WCFTestClient.exe 上说
LINQ to Entities 不支持指定的类型成员“选项”。仅支持初始化程序、实体成员和实体导航属性。