Click here to Skip to main content
13,152,454 members (39,011 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
var foo = (TSDataBase.Staff.Where(p => p.TimeSheet.All(c =>c.tsDate<> 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 1-Sep-12 22:13pm
Updated 1-Sep-12 23:32pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try This one:
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<
                                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.

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:

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;
                                select sheet;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170924.2 | Last Updated 2 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100