tags:

views:

229

answers:

3

I have a LINQ query which checks to see if there are any tests done since the beginning of the year.

var MetersTestedCount = (from n in _mttDomainContext.MTTMeterTests
                              where n.TestDate > DateTime.Parse("1/1/2010")  
                              select n.TestDate).Count();

This query however returns an empty set. I have a similar SQL query which pulls some records,

USE MeterTestTracking
Select * From MTTMeterTest
WHERE TestDate > '1/1/2010'

I have been to the previous posts. Even though similar, still no help:

How to compare just the date, not the timestamp using LINQ

and

How to compare dates in LINQ?

What's the correct way to check dates in LINQ to return a dataset?

A: 

How about explicitly stating the format of the date string you're converting i.e. use

DateTime.Parse("1/1/2010", "dd/MM/YYYY")
Raj
Thanks for the quick answer, but it is complaining about DateTime.Parse not accepting those parameters.
Redburn
+1  A: 

Have you tried creating a DateTime instance?:

var MetersTestedCount = (from n in _mttDomainContext.MTTMeterTests
                              where n.TestDate > new DateTime(2010,1,1).Date  
                              select n.TestDate).Count();
Thomas
Still no results back
Redburn
@Redburn - Using SQL Profiler, what is the query from the above code that was sent to the server?
Thomas
Ending up tracing the error using this. Thanks!
Redburn
A: 

Run SQL profiler (if you have MS SQL 2005 or higher) and check what queries are executed. Or try Linq2Sql visualizer which shows you generated SQL and/or results.

Karel Frajtak