mardi 11 août 2015

how to get data in a IQueriable from two table using LINQ

I have a IQueryable in my MVC code as below

   IQueryable<hdr> data = db.hdr.Where(m => m.created_by == created_id &&
 m.client_id == client_id).OrderBy(m => m.request_id);

and using the data given by the user i will filter this accordingly

eg:= If user supply id

  data = data.Where(m => m.created_by == created_id && 
m.client_id == client_id && m.request_id == id).OrderByDescending(m => m.request_id);

so it will filter the result in to row having the id provided by user.

I have another filter called staff id this staff id is coming under detail table not in this hdr table

the normal query for getting the header row with the staff id provided is

select h.*
from hdr h,
     dtls d
where h.request_id = d.request_id
and d.employee_id = '055'

but i don't have any idea how to convert the same to linq and assign to the IQueryable data

give some idea about this.

Aucun commentaire:

Enregistrer un commentaire