Posted on 2010-01-05
Last Modified: 2013-11-11
Came across a problem with nullable datetime columns and linq query.   Essentially I cannot query on datetime if the field is null in the database.

What is the best approach when adding a customer record with linq to sql server and setting a default value for the Date of Birth (DOB) column.

For the user the DOB is optional but I need to do a query that will return all records that have a DOB say greater than 1955.  

So what I need is a default value that is set and cannot be a valid date of birth but will also work with a linq query

For example

          var Data = from qryData in ReportData
                         where (qryData.DOB >= DOB)
                         select qryReportData;

Question by:mugsey
    LVL 96

    Accepted Solution

    The DateTime.MinValue is 1/1/0001 12:00 am, and can be used in place of NULL in a database.

    Author Comment

    Thanks Bob

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now