tags:

views:

37

answers:

3

Hi All,

How to write linq query to access data from multiple table.How do you write Linq query for the following sql query:-

"select * from user,employee where user.Name='smith' and employee.company='xyz'"
A: 

It depends on which linq provider you use. For example, assuming you have the foreign keys defined correctly, entity framework creates what they call "Navigation Properties". So you can easily write a linq query like the above in this fashion:

var query = data.Where(employee => employee.Name == "Smith" && employee.Company.Name == "xyz");
Joel Martinez
+1  A: 

Something like this would do it.

var q = from u in db.user
        from e in db.employee
        where u.Name == "smith" && e.company == "xyz"
        select new
        {
           User = u,
           Employee = e
        };
juharr
A: 
var result = from u in context.User
             from e in context.Employee
             where (u.Name == "smith" && e.company == "xyz")
Justin Niessner