Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
    
Just a note: What are you doing with ops. Looks like you're populating it only to discard it. – Brian Rasmussen Aug 7 '13 at 21:50

Ran into similar issue. I was able to get around it by calling ToList() on the query and then a separate query for Select new {... }

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.