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 5995851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:01:11+00:00 2026-05-23T00:01:11+00:00

I am using the entity framework 4 with edmx files and POCOs within an

  • 0

I am using the entity framework 4 with edmx files and POCOs within an asp.net mvc application.

First of all I have a person class which is mapped to a table in the database.

public class Person
{
    public Int32 ID{get;set;}
    public string Name{get;set;}
    public Int32? ParentID{get;set;}
}

Then in my service layer I have the following function to retrieve all persons. If a parentID is supplied the persons retrieved will be the ones with that parentID:

public List<Person> Get(int? parentPersonID = null)
{
    var persons = Repository().GetAll(c => c.ParentID == parentPersonID);
}

Finally, the Repository() function returns an IRepository<Person> which contains the method:

public IQueryable<TModel> GetAll(Expression<Func<TModel, bool>> predicate = null)
{
    var result = ObjectSet.AsQuaryable(); //ObjectSet is a ObjectSet<Person> instance
    if (predicate != null)
        result = result.Where(predicate);
    return result;
}

Now, the problem is that if I pass null as parentPersonID to the service layer, so as Get(null). Enumeration yields no results. However if I modify the service layer code to:

public List<Person> Get(int? parentPersonID = null)
{
    var persons = Repository().GetAll(null);
}

everything works as expected.

Any ideas why is that?

EDIT:
If i replace the service layer function code with:

var persons = Repository().GetAll(c => c.ParentID.Equals(parentPersonID));

instead of:

var persons = Repository().GetAll(c => c.ParentID == parentPersonID);

it works as expected – the first line retrieves records from the DB whereas the second one does not.
I am still curious as to what is the difference in the Equals() and == in this case.

  • 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-23T00:01:12+00:00Added an answer on May 23, 2026 at 12:01 am

    I suspect it’s to do with how equality is being handled. Try this:

    public List<Person> Get(int? parentPersonID = null) {
        var persons = Repository().GetAll(parentPersonID == null ? 
              c => !c.ParentID.HasValue :                
              c => c.ParentID == parentPersonID);
        ... 
    }
    

    This will change the predicate to be an explicit nullity check when you pass in a parentPersonID of null, rather than making it just match the value you’ve passed in. There may well be a more elegant way of expressing it, but it’s worth at least trying that to start with.

    (I assume that if you specify a parentPersonID of null you want to get all the people with a null parentPersonID, not just all the people… that would be a different change.)

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

Sidebar

Related Questions

First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
I am working on an MVC application using Entity Framework. After creating an EDMX,
In my application I'm using Entity Framework 4.0 Model First. I have several tables
We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the
I have a edmx file created using the entity entity framework model. Whenever I
I am using Entity Framework with my website. To improve performance, I have started
I'm using Entity Framework in my project, and I have the problem that, once
I am using Entity Framework 4 in a desktop application with SQL Compact. I

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.