This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi all, I'm trying to use linq to select entities that are created on a specific day, however I'm having trouble with the query. I'd like to do this:
from u in Users where u.CreatedOn.Date == date orderby u.CreatedOn select u But that gives me the message "The method 'Date' is not supported." Using the whole field gives me the time as well, so I'm looking for another way of getting only the date part out of the CreatedOn field. Any ideas?
|
|
|
What database are you using? |
|
|
Sql Server 2005 and 2008. |
|
|
If you can get away with only supporting 2008, upgrade to LightSpeed 3.11 -- we added 2008 support for the Date property. If you also need to support 2005, you'll need to query explicitly by day, month and year: u.CreatedOn.Day == date.Day |
|
|
Ah, great! Thanks for your quick support as always, Ivan. :) |
|
|
As a follow-up, I also tried to use AddHours() but it wasn't supported as well. What is the best way of comparing dates on the database side using Lightspeed/LINQ?
|
|
|
By eerie coincidence, the last thing I did last week was to add support for AddHours, AddMinutes and AddSeconds! So if you download the current nightly they should be in there. (SQL Server 2005 and 2008 only at the moment -- let me know if you need them on other platforms.) Haven't done AddDays etc. yet but will try to get them in shortly. |
|
|
Also, if there are any other DateTime methods/properties that you'd like to see implemented while I'm in there, let me know -- not making any promises, but it doesn't hurt to ask! |
|
|
Wow, nice coincidence! :) The Add() method would be quite useful, if it's possible? I guess it differs quite a bit between databases...
|
|