If you want to join data which is in a list with data that is in the database, then you need to use the 'Contains' operation.
The code below shows that we have a list containing two values, next we want to join this list with some data in the database. This data has an Id and an Description.You might be tempted to use the join operator, but that will fail, instead, call the Contains() method.
static void Main(string[] args){ List<int> l = new List<int>(); l.Add(1); l.Add(2);
CustomerInfoDBDataContext db = new CustomerInfoDBDataContext(); var result = from pi in db.PersonalInfos where l.Contains(pi.Id) select pi.Id + " - " + pi.Description;
foreach (var info in result) { Console.WriteLine(info); } Console.ReadLine();}
dasBlog theme by Mads Kristensen
Concepts LINQ Entity Framework WCF WPF RESTful Web Unit Testing .NET Workflow More >>
Tools Visual Studio Windows IIS Silverlight More >>
Type Screencast Tools Video Newsletter Sample Article Books Magazine How To Demo Course Products More >>