I am using Subsonic (SimpleRepository) to query my SQL 2008 database. I am trying to write a query that will calculate the number of days between two fields and return records where the difference is less than a given number. However, I get a "The member 'Days' is not supported" error.
Can anybody suggest an alternative query?
Here's the query I'm trying to run:
var repository = new SimpleRepository("MyConnection",
SimpleRepositoryOptions.None);
var query = (from c in repository.All<Data.Customer>()
where c.LastSynchronizedOn == null ||
(c.LastSynchronizedOn - c.CreatedOn).Days <= 7)
select c).Distinct();
EDIT:
I tried:
(c.LastSynchronizedOn == null || (c.LastSynchronizedOn.Value - c.CreatedOn).Days <= 7)
I get the same exception: The member 'Days' is not supported
I also tried:
(c.LastSynchronizedOn == null || ((c.LastSynchronizedOn - c.CreatedOn) > new TimeSpan(7, 0, 0, 0)))
I get: Failed to convert parameter value from a TimeSpan to a String.
Best Answer
Please check the data type of fields
LastSynchronizedOn
andCreatedOn
as the problem is not related to SubSonic but .Net is complaining (if this is right way to put it) because the expression(c.LastSynchronizedOn - c.CreatedOn)
might not be returningDateTime
object.EDIT:- as per your comment please try this
EDIT (2): the statement
returns boolean (true or false)
try this: