?
Solved

LINQ HOW TO SET DEFAULT MIN VALUE IN SMALDATETME COLUM

Posted on 2010-01-05
2
Medium Priority
?
366 Views
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;

0
Comment
Question by:mugsey
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 26181317
The DateTime.MinValue is 1/1/0001 12:00 am, and can be used in place of NULL in a database.
0
 

Author Comment

by:mugsey
ID: 26181352
Thanks Bob
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

839 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