2

I'm wondering how and if I can query on multiple strings/ints easily doing something like this?

var test = from a in db.PlasserLans
from b in db.Ulans
where a.registeredNick == b.Username &&
a.Nick == {"Ayuris" , "Crey" , "DjMofasa" , "esel" , "Firaxa" , 
           "Kindleguy" , "Michigo" , "moiC" ,"Shibiz"}
orderby a.Nick
select new
{
    Nick = a.Nick,
    Username = b.Username,
    Email = b.UserEMail,
    RealName = b.UserRealname,
};

2 Answers 2

3

You can create the list before the query, that would make it easier to understand. Also you can do a join instead of looping on both tables.

List<string> nickList=new List<string> {"Ayuris" , "Crey" , "DjMofasa" , "esel" , "Firaxa" , "Kindleguy" , "Michigo" , "moiC" ,"Shibiz"};

var test = from a in db.PlasserLans
           join b in db.Ulans
           on a.registeredNick equals b.Username
           where nickList.Contains(a.Nick)
           orderby a.Nick
           select new
                  {
                      Nick = a.Nick,
                      Username = b.Username,
                      Email = b.UserEMail,
                      RealName = b.UserRealname,
                  };
Sign up to request clarification or add additional context in comments.

Comments

1

In Linq-2-sql its just the other way around

 where .... &&
 {"Ayuris" , "Crey" , "DjMofasa"}.Contains(a.Nick)

This is by heart, not sure if the direct usage of {} works, but you need to checkout the .Contains() for linq-2-sql and it will work.

1 Comment

I had to make it a array first running it directly on the {} don't work. got it to work using your way indirectly

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.