2

I am trying to understand the to Sql SelectMany. I want to use it in the query below to see how the results are generated using SelectMany as against Select. I know I can just use a select here instead...I have a table users with Id as int and location as a string. When I run the query below I get the exception "Sequence Operators not supported for type System.String". Can you please tell me how do I iterate the results that are returned by SelectMany and print the results to console.

UsersDataContext db = new UsersDataContext(); var results = db.Users.Where(u=> u.ID == 5 || u.ID == 6).SelectMany(u => u.Location); foreach (var c in results) { Console.WriteLine(c); } 

1 Answer 1

2

You should use .Select here.

From MSDN on SelectMany:

Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.

Basically SelectMany works on taking a lambda pointing to a collection and then flattening it into a single resultset. Location in your example isnt a collection

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.