4

I need to compare and get the matching values from a string list with LINQ. Have a look at my code.

Code

Split = Id.Split(',');
List<string> uids = new List<string>(Split);
var model = (from xx in Db.ItemWeedLogs
                where xx.ItemNo == uids   
                // I need to pass a string list to extract the matching record.
                select xx).ToList();
1
  • 1
    omg so late :/ this people so fast. Commented Dec 11, 2012 at 13:18

3 Answers 3

7

Try this :

var model = (from xx in Db.ItemWeedLogs
                     where uids.Contains(xx.ItemNo)
                     select xx).ToList();
Sign up to request clarification or add additional context in comments.

Comments

2

Try:

where uid.contains(xx.ItemNo)

1 Comment

@Dheyv You are more than welcome. You should accept Wahid's answer (he was first and clearer ;)
2

I think this is much more faster and clear.

var model = Db.ItemWeedLogs
              .Join(Id.Split(','), di => di.ItemNo, si => si, (d, s) => new {d})
              .ToList();

1 Comment

+1 , depending on the relative sizes of the collections, building up a dictionnary might be a good option too

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.