Click here to Skip to main content
15,914,225 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need to fetech
One Staff from Table:Staff where Staff.StaffID=2
and All respective Item from Table:TimeSheet where TimeSheet.tsDate < Today

I was using the following
--------------------------------------------------------------
C#
var foo = (TSDataBase.Staff.Where(p => p.TimeSheet.All(c =>c.tsDate<datetime.today))).single(g> g.StaffID == EmpID);

------------------------------------------------------------

It one returning Satff-data but respective Timesheet is null though it is there.

Classes/ Relatios are defined for this tables..

Can anyone help me?
Posted
Updated 1-Sep-12 23:32pm
v2

1 solution

Try This one:
C#
var TheMember = from member in TSDataBase.Staff
                where member.StaffID == EmpID
                select new
                {
                    Name = member.Name,
                    Position = member.Position,
                    // and so on based on your Staff table
                    TimeSheetData = from sheet in TSDataBase.TimeSheet
                                where sheet.StaffID = member.StaffID
                                and sheet.tsDate<datetime.today
                                select sheet;
                };

The first part selects the staff data. As I don't know about the members of there two classes, I made my assumptions. The second part (like a inner select) will fill the TimeSheetData member of the newly created anonymous class (you should create a dedicated class for that) will be filled with the timesheet "records" related to that staff member according to the condition.

Update:
By the way your question and your fluent api query are confusing. You tell about tables, but you select from an embedded IQueryable. Let's asume used EF DatabaseFirst, and you have navigation on place. Than the above query will look like this:

XML
var TheMember = from member in TSDataBase.Staff
                where member.StaffID == EmpID
                select new Staff
                {
                    Name = member.Name,
                    Position = member.Position,
                    TimeSheet = from sheet in member.TimeSheet
                                where heet.tsDate&lt;datetime.today
                                select sheet;
                };
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900