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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:58:46+00:00 2026-05-24T20:58:46+00:00

I em using Linq to EF and trying to get FirstOrDefault entitiy from ObjectSet.

  • 0

I em using Linq to EF and trying to get FirstOrDefault entitiy from ObjectSet.
The query looks like this :

        Notification not = new Notification();
        ........
        //not.SubTypeID = null;

        var elem = ent.Notifications.FirstOrDefault(p =>                     
                    p.ID == not.ID &&
                    p.SubTypeID == not.SubTypeID &&
                    p.Location == not.Location &&
                    p.TypeID == ns.TypeID
            );

Sometimes SubTypeID can be null and in this case nothing is returnced in elem althogh p.SubTypeID and not.SubTypeID are both null.

But the strange thing is that when I run this query :

        var elem = ent.Notifications.FirstOrDefault(p =>                     
                    p.ID == not.ID &&
                    p.SubTypeID == null &&
                    p.Location == not.Location &&
                    p.TypeID == ns.TypeID
            );

everything works as expected and I see data in elem.

So what I am doing wrong and what is the difference between these 2 queries when not.SubTypeID is null.

  • 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-24T20:58:47+00:00Added an answer on May 24, 2026 at 8:58 pm

    In C#, the result of null == null is true. But in SQL, which this expression tree is getting compiled into, the result of NULL = NULL is NULL. Example on PostgreSQL:

    SELECT 1 WHERE NULL = NULL;
     ?column?
    ----------
    (0 rows)
    

    You might consider using an expression like:

    p.SubTypeID == not.SubTypeID ||
    (p.SubTypeID == null && not.SubTypeID == null)
    

    This is kind of a hack, and there may be a better solution than this. But the NULL = NULL test is likely the root of your problem.

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

Sidebar

Related Questions

Ok, I'm trying to get this working. This is my first time using LINQ.
I'm trying to get a paged query to work properly using LINQ and NHibernate.
I am trying to insert a record into a table using Linq but get
I am trying to parse an RSS feed using Linq to XML like so:
I'm using an ADO.NET Entity Model which I'm trying to query using LINQ. The
I'm trying to get an insert to work using LINQ and am having some
I am trying to get serialized results from a WCF service from database using
I am trying to get the following: [today's date]___[textfilename].txt from the following code: using
I am trying to get a total record count from the below Method using
I am new to using LINQ. I am trying to use it in Silverlight

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.