Linq with Datetime

3 posts, 1 answers
  1. Herbert
    Herbert avatar
    4 posts
    Member since:
    Aug 2012

    Posted 04 Sep 2012 Link to this post

    Hi,

    I've a curious problem with a linq query that accesses a datetime field and I believe this is a bug.
    My table structure is as follows:
    CREATE TABLE Record
    (
    id Int IDENTITY(1,1) NOT NULL,
    propTime DateTime NOT NULL
    ...
    )

    Linq query:
    var test = Database.AllRecords
        .Select(x => new
        {
            date = x.PropTime.Date
        }).ToList();

    This generates the following SQL statement for the VistaDB backend:
    SELECT
        DATEADD(
            dd,
            DATEDIFF(dd, GETDATE(), a.[PropTime]),
            GETDATE()
        ) EXPR1
    FROM [Record] a

    So results returned from this statement are incorrect.
    For example if the table contains a row ('1', '2011-01-03 00:02:08'), I expect '2011-01-03 00:00' to be returned. But I get '2011-01-03 21:35:15 ' and this is not correct.

    How can I fix this ?

    Thank you

    Herbert
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 06 Sep 2012 Link to this post

    Hi Herbert,

    This is a known issue which has been fixed and the fix will be part of the upcoming internal build, expected next week. Beside this fix the new version will contain support for other DateTime operations like AddDays, AddHours(), etc.

    In the meantime you could use a workaround similar to this:
    var query = Database.AllRecords.Select(x => x.PropTime).ToList();
    var test = query.Select(x => new
                {
                    date = x.PropTime
                });
    This will select the whole DateTime values and then extract the date parts on the client.

    We will notify you in this thread when the new build is available, so you can remove the workaround and use the initial code. Please excuse us for the inconvenience caused.

    All the best,
    Alexander
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
  4. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 25 Sep 2012 Link to this post

    Hello Herbert,

    The internal build with the necessary fix is finally released. You should be able to download it from your account, the new version is 2012.2.924.1.
    Please excuse us for the delay.

    Regards,
    Alexander
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top