Using LINQ to fetch result from nested SQL queries
- by Shantanu Gupta
This is my first question and first day in Linq so bit difficult day for me to understand.
I want to fetch some records from database
i.e.
select * from tblDepartment
where department_id in
(
select department_id from tblMap
where Guest_Id = @GuestId
)
I have taken two DataTable. i.e. tblDepartment, tblMap
Now I want to fetch this result and want to store it in third DataTable.
How can I do this.
I have been able to construct this query up till now after googling.
var query = from myrow in _dtDepartment.AsEnumerable()
where myrow.Field<int>("Department_Id") == _departmentId
select myrow;
Please provide me some link for learning Linq mainly for DataTables and DataSets.
EDIT:
I have got a very similar example here but i m still not able to understand how it is working.
Please put some torch on it.