0

This is my LINQ:

var context = new CYGNETEntities();
var users = (from u in context.mUsers
             where u.userName == EmailID && u.password == Password
             select new 
             { 
                 u.userName,  
                 u.firstName,  
                 u.lastName  
             })
    .AsEnumerable()
    .Select(x => string.Format("{0}, {1}, {2}", x.userName, x.firstName, x.lastName))
    .ToArray();

Here, the actual values are below:

   u.userName = "admin"
   u.firstName = "fname"
   u.lastName = "lname"

So, the linq returns as below:

users[0] = admin, fname, lname

But I want the linq records in string array such as below:

   users[0] = admin
   users[1] = fname
   users[2] = lname

Any suggestions please?

2
  • You can split the users array by comma, and you will get your result. Commented Oct 15, 2015 at 11:49
  • this has to be a 2-dimensional array in case that you have 2 results with the same EmailID and Password Commented Oct 15, 2015 at 11:49

1 Answer 1

2

I haven't tested this, but what about:

var users = (from u in context.mUsers
              where u.userName == EmailID && u.password == Password
              from s in new string [] { u.username, u.FirstName, u.LastName }
              select s).ToArray();
Sign up to request clarification or add additional context in comments.

1 Comment

He's using a SelectMany, so he needs the .ToArray().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.