I am creating a quiz in which have following class
Quiz
with properties CorrectOption
, WrongOption1
, WrongOption2
, WrongOption3
.
in its DTO
i have the List<String> Options
that will contain all wrong and correct options.
While retrieving the entities i am using object initializer of DTO but don't know how to assign List<String> Options
.
I remember we use the anonymous methods to do so.
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();
}
};
but it gives following error.
Cannot convert lambda expression to type 'System.Collections.Generic.List' because it is not a delegate type.
UPDATE
For instance i have created a read only property on original entity class to do the work. but plz let me know the better way. Thanks
UPDATE2
But it didn't work :p says following on WCFTestClient.exe
The specified type member 'Options' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
ops
. Looks like you're populating it only to discard it. – Brian Rasmussen Aug 7 '13 at 21:50