Click here to Skip to main content
11,923,676 members (65,831 online)
Rate this:
Please Sign up or sign in to vote.
See more: LINQ MVC3
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 23:13pm
Edited 2-Sep-12 0:32am

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 | Mobile
Web04 | 2.8.151125.3 | Last Updated 2 Sep 2012
Copyright © CodeProject, 1999-2015
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