DateTime datatype column syntax in a entity model query in ASP.NET MVC

I'm working on an ASP.NET mvc application.
I'm using Visual Studio 2013.
I created a Entity Model of the Employees table of the Northwind sql server database.
The name of my model is EmployeesMode.edmx.

In the Models folder along with the model I have a class called ModelService.cs which holds the queries I am going to us in my WebGrid filter.

My question is in regards to this snippet:

        private static IQueryable<Employee> filterPeople(int? employeeID, string lastName, string firstName, string title, string titleOfcourtesy, DateTime? birthDate, string address, string city, string region, string postalCode, string country, string homePhone, IQueryable<Employee> query)
            // EmployeeID
            if (employeeID != null)
                query = query.Where(p => p.EmployeeID == employeeID);
            // LastName
            if (!string.IsNullOrWhiteSpace(lastName))
                query = query.Where(p => p.LastName.Contains(lastName));
            // FirstName
            if (!string.IsNullOrWhiteSpace(firstName))
                query = query.Where(p => p.FirstName.Contains(firstName));
            // Title
            if (!string.IsNullOrWhiteSpace(title))
                query = query.Where(p => p.Title.Contains(title));
            // TitleOfCourtesy
            if (!string.IsNullOrWhiteSpace(titleOfcourtesy))
                query = query.Where(p => p.TitleOfCourtesy.Contains(titleOfcourtesy));
            // BirthDate
            if (!string.IsNullOrWhiteSpace(birthDate))
                query = query.Where(p => p.BirthDate.ToString().Contains(birthDate));

            // Address
            if (!string.IsNullOrWhiteSpace(address))
                query = query.Where(p => p.Address.Contains(address));
            // City
            if (!string.IsNullOrWhiteSpace(city))
                query = query.Where(p => p.City.Contains(city));
            // Region
            if (!string.IsNullOrWhiteSpace(region))
                query = query.Where(p => p.City.Contains(region));
            // PostalCode
            if (!string.IsNullOrWhiteSpace(postalCode))
                query = query.Where(p => p.PostalCode.Contains(postalCode));
            // Country
            if (!string.IsNullOrWhiteSpace(country))
                query = query.Where(p => p.Country.Contains(country));
            // HomePhone
            if (!string.IsNullOrWhiteSpace(homePhone))
                query = query.Where(p => p.HomePhone.Contains(homePhone));

            return query;

Open in new window

i'm getting an error on the birthDate column because its a DateTime data time.

This pic shows I'm not declaring this datetime column correctly
my error
Anyone know the syntax to declare a DateTime column?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Your problem is that the parameter:

Snippet declared as a nullable DateTime, but you are trying to use it like a string. The if clause should be:

if (birthDate.HasValue)

Open in new window

...and I suppose the body would be:

query = query.Where(p => p.BirthDate == birthDate)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.