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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:01:59+00:00 2026-05-13T11:01:59+00:00

I came across a rather strange problem with linq-to-sql. In the following example, var

  • 0

I came across a rather strange problem with linq-to-sql. In the following example,

var survey = (from s in dbContext.crmc_Surveys
                                   where (s.crmc_Retail_Trade_Id == tradeId) && (s.State_.Equals(state))
                                   select s).First();

If tradeId is null, it doesn’t behave as if I had specified null specifically like this instead,

var survey = (from s in dbContext.crmc_Surveys
                                   where (s.crmc_Retail_Trade_Id == null) && (s.State_.Equals(state))
                                   select s).First();

Which is my desired behavior. In fact it doesn’t return anything unless both values are non-null. I can’t figure out how to accomplish this short of several different linq queries. Any ideas?

  • 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-13T11:01:59+00:00Added an answer on May 13, 2026 at 11:01 am

    Change where (s.crmc_Retail_Trade_Id == tradeId)
    to

    where (s.crmc_Retail_Trade_Id == tradeId || 
          (tradeId == null && s.crmc_Retail_Trade_Id == null))
    

    Edit – based on this post by Brant Lamborn, it looks like the following would do what you want:

    where (object.Equals(s.crmc_Retail_Trade_Id, tradeId))
    

    The Null Semantics (LINQ to SQL) MSDN page links to some interesting info:

    LINQ to SQL does not impose C# null or
    Visual Basic nothing comparison
    semantics on SQL. Comparison operators
    are syntactically translated to their
    SQL equivalents. The semantics reflect
    SQL semantics as defined by server or
    connection settings. Two null values
    are considered unequal under default
    SQL Server settings (although you can
    change the settings to change the
    semantics). Regardless, LINQ to SQL
    does not consider server settings in
    query translation.

    A comparison with the literal null
    (nothing) is translated to the
    appropriate SQL version (is null or is
    not null).

    The value of null (nothing) in
    collation is defined by SQL Server;
    LINQ to SQL does not change the
    collation.

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

Sidebar

Related Questions

I came across this rather unusual usage of 'delete'. Just wanted to know if
I recently came across a rather unusual coding convention wherein the call for a
Recently I came across a gcc extension that I have found rather useful: __attribute__(cleanup)
I came across a rather unusual way to build an object of a class
I just came across this in some code, and I'm rather confused. timer =
I have a fairly limited knowledge of Java development. I came across the following,
Came across this error today. Wondering if anyone can tell me what it means:
I came across this article written by Andrei Alexandrescu and Petru Marginean many years
I came across a printed article by Bertrand Meyer where he states that tests
I came across this recently, up until now I have been happily overriding the

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.