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'"
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'"
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");
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
};
var result = from u in context.User
from e in context.Employee
where (u.Name == "smith" && e.company == "xyz")