Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:50:59+00:00 2026-06-13T01:50:59+00:00

I am building an ASP.Net MVC 3 Web application which uses Entity Framework 4.1.

  • 0

I am building an ASP.Net MVC 3 Web application which uses Entity Framework 4.1. I also use the Unit of Work pattern with a Generic Repository. I have two Entities in my Model, Shift and ShiftDate. Please see the diagram below for their structure. The idea is, a Shift can have 1 or many ShiftDates, and a ShiftDate can belong to only one Shift.

enter image description here

I wish to create a query which will return a List of all Shifts like so

public IList<Shift> GetShifts(int id)
{
   return _UoW.Shifts.Get(s => s.organisationID == id).OrderBy(s => s.startDate).ToList();
}

Then in my Razor View, I wish to use a foreach loop and list the details of each Shift. One of these details is the total number of ShiftDates each Shift has. To do this I will do something like

foreach(var shiftDate in Model.Shifts)
{
    @Html.DisplayFor(modelItem => item.ShiftDates.Count)
}

This works fine, however, I want the count to exclude ShiftDates whose shiftDateStatusID is set to 442. To do this I tried amending my Linq Query to this

return _UoW.Shifts.Get(s => s.organisationID == id && s.ShiftDates.Any(sd => sd.shiftDateStatusID != 442))
.OrderBy(s => s.startDate).ToList();

However, this still pulls back ShiftDates who have a shiftDateStatusID of 442.

Hopefully this makes sense.

Any feedback would be greatly appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:51:00+00:00Added an answer on June 13, 2026 at 1:51 am

    If you do

    _UoW.Shifts.Get(s => s.organisationID == id
                         && s.ShiftDates.Any(sd => sd.shiftDateStatusID != 442)
    

    you get shifts that have at least one ShiftDate having a shiftDateStatusID other than 442. Well, there are probably a lot of shifts meeting this condition. The ShiftDates collections of these shifts will be loaded completely, including those with 442 (if any).

    Either you have to exclude the ShiftDates with status 442 when you populate your view model, or when it’s only for the count, exclude them when you do the count:

    item.ShiftDates.Count(sd => sd.shiftDateStatusID != 442)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an ASP.Net MVC 3 Web application with Entity Framework 4.1. I
I am building an ASP.NET MVC web application using entity framework DbContext using the
I am building an ASP.Net MVC 3 web application using Entity Framework 4.1 with
I am building an ASP.Net MVC 3 Web application using Entity Framework 4.1. To
I am building an asp.net mvc web application. Do I need to use captcha
I'm building an application which (currently) consists of one web application (ASP.NET MVC) and
I'm am building my asp.net web application using MVC (Preview 5), and am also
I am building a web application using ASP.NET MVC that has two very distinct
I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET
I'm in the process of building my first web application using ASP.NET MVC 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.