Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 04, 2010 01:42 PM by mylok
Sep 30, 2010 09:54 AM|LINK
I have a problem which the were clause in my LinqToSql Query, here is an extract...
private void GetUsersByDOB(DateTime? DOB)
from usr in GetUsers() // returns IQueryable of users
where usr.tblContact.DateOfBirth == (DOB != null ? DOB : usr.tblContact.DateOfBirth)
The query works when a DOB is passed in (weather its null or has a value).... but the problem is, if the data in the DB is NULL, these are never returned whatever the input is.
It's to do with the evaluation of "where usr.tblContact.DateOfBirth == usr.tblContact.DateOfBirth" - am i doing this correct?
Sep 30, 2010 10:47 AM|LINK
usr.tblContact.DateOfBirth is null or usr.tblContact.DateOfBirth == (DOB != null ? DOB : usr.tblContact.DateOfBirth)
Sep 30, 2010 12:57 PM|LINK
I think "where usr.tblContact.DateOfBirth == usr.tblContact.DateOfBirth" is correct. You can use sqlprofile or linqpad check the sql code.
From your when DOB is null will return all users is that what you want?
Oct 01, 2010 07:45 AM|LINK
Thanks for the reply...
im not sure the first suggestion is correct because that will ALWAYS return null values.... this is part of a search engine and I only want null values returned if the input (DOB) is null.
However, as it stands, the null entries in the DB are never returned whatever the input is.
The second comment, yep this is what I thought, but it doesn't give me my DateTime fields from the database that have a NULL value in them.
Oct 01, 2010 03:31 PM|LINK
"it doesn't give me my DateTime fields from the database that have a NULL value in them "
when you run your query did you get any data return except the NULL?
Oct 04, 2010 07:22 AM|LINK
Yep, all the other data is still returned
Oct 04, 2010 01:42 PM|LINK
Did you debug the DOB value you pass to GetUsersByDOB method?
It seems nothing wrong with your query, I suspect the DOB value you pass to the method never be null