tags:

views:

31

answers:

1

I am trying to perform the following linq to entities query-

var data = DataContext.Employee.Where(e=>e.Date.Year>1986).ToList();

Now the problem is that Date field is a nullable DateTime field and I can't access Year property and on the database side I can't change legacy code! ....anyways is there anyway possible to use the year property?

+4  A: 
var data = DataContext.Employee
    .Where(e=>e.Date.HasValue && e.Date.Value.Year>1986).ToList();

Note that this will not include Employees without a date in the list.

Yuriy Faktorovich
out of curiosity, will LINQ2SQL see this and translate it to SQL or pull down all records and perform the lambda in code?
NickLarsen