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

  • SEARCH
  • Home
  • 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 6957319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:59:09+00:00 2026-05-27T14:59:09+00:00

When I do the query: Users.OfType<Student>().Where(u => u.StudentClasses.Any(sc => sc.Class.TermId == 1 && sc.Class.SubFormId

  • 0

When I do the query:

Users.OfType<Student>().Where(u => u.StudentClasses.Any(sc => sc.Class.TermId == 1 && sc.Class.SubFormId == 1))

I get nothing. But this query returns true:

StudentClasses.Any(sc => sc.Class.TermId == 1 && sc.Class.SubFormId == 1)

So basically this is the same as:

Users.OfType<Student>().Where(u => true)

Which returns all the students. So OfType<Student> works.

I’m 100% sure that there are students in these classes StudentClasses but for some reason I get back no student although the subquery returns true.

Student is inherited from User, but only Student has StudendClass. What would be wrong with this query?

I basically want students in a particular subform/term (all these properties are in a Class.

I’m using Table per heirachy. Model builder:

modelBuilder.Entity<User>()
            .Map<Teacher>(m => m.Requires("UserType").HasValue("Teach"))
            .Map<Student>(m => m.Requires("UserType").HasValue("Stu"))
            .Map<Staff>(m => m.Requires("UserType").HasValue("Staff"));

Edit:

This also returns nothing:

Users.OfType<Student>().Where(u => u.StudentClasses.Any(sc => true))
  • 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-05-27T14:59:09+00:00Added an answer on May 27, 2026 at 2:59 pm

    I’m 100% sure that there are students in these classes StudentClasses.

    I am 99% sure there aren’t. (1% for the potential case you have discovered some serious EF bug.) If there are students in classes with Class.TermId == 1 and Class.SubFormId == 1 your query must return those students.

    Your test query…

    (context.)StudentClasses.Any(sc => sc.Class.TermId == 1 && sc.Class.SubFormId == 1)
    

    …has nothing to do with your original query. It only says that there is at least one row in the StudentClasses table with Class.TermId == 1 and Class.SubFormId == 1.

    It doesn’t prove that you have any student which is in this particular class (or in these particular classes if there is more than one class with Class.TermId == 1 and Class.SubFormId == 1). All your students could be in the other classes and your original query would correctly return no student as result. So, this is by no means identical with (context.)Users.OfType<Student>().Where(u => true).

    If you are still 100% sure you should show the content of your tables in a small example to make the problem reproducable for us.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's wrong with this query: INSERT INTO Users( weight, desiredWeight ) VALUES ( 160,
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
I've got a php script with this statement: $query = SELECT type FROM users
I have identified the query constructs my users normally use. Would it make sense
I currently have a query similar to: SELECT users.fname, users.lname, sales.date FROM users LEFT
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have a query returning 24 records for users with code A and 54
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I currently have the query running on Postgres: SELECT * FROM addenda.users WHERE users.username
I need to query AD to determine if a users account is disabled. Using

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.