How to fetch data on basis of multiple Id in LINQ or EF ?


Hi
Recently one of my project, there was requirement to filter from one table on basis of multiple Id. There was using EF. So in EF we can write the Syntax like this

using (DemoJobPortalModel.DemoJobPortalEntities objE = new DemoJobPortalModel.DemoJobPortalEntities())
{
List<int> ListCountryId = new List<int> { 3, 5, 7 };

var query = from m in objE.tblCountries
where ListCountryId.Contains(m.Id)
select m;
GridView1.DataSource = query;
GridView1.DataBind();
}

In Sql Server we can do like this

Select *from tblCountry where Id in (3,5,7)

Advertisement

One thought on “How to fetch data on basis of multiple Id in LINQ or EF ?

  1. Fenil April 1, 2012 / 4:18 pm

    Helloo Chandradev,

    in crictell

    mere main error aa rahi hai in api connection … please send me the full code ….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.