0

我正在创建一个测验,其中包含以下课程

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 不支持指定的类型成员“选项”。仅支持初始化程序、实体成员和实体导航属性。

4

1 回答 1

0

遇到类似的问题。ToList()我可以通过调用查询然后单独查询 Select new {... }来绕过它

于 2013-08-07T20:44:57.533 回答