MD GHOUSE MD GHOUSE - 8 months ago 31
SQL Question

how to convert this query into linq

Please help me how to convert sql query into linq & also if in future i have any query to change is their any online solution is their for converting sql query into linq

emp e Inner join
Country s on e.countryId=s.CountryId


Use the following:

var result =  from t1 in db.Table1 
              join t2 in db.Table2 on t1.field equals t2.field 
              select new { t1.field2, t2.field3 };

The above join two tables and returns required data.

So your query would be like:

   var result =  from e in db.emp 
                 join s in db.Country on e.countryId equals s.CountryId 
                 select new { e.countryId, s.CountryName };

I would suggest to learn the basics of Linq and use this link to study:

By the way, you can use LinqPad to practice Linq and it is a good tool.