This is a migrated thread and some comments may be shown as answers.

Linq with Datetime

2 Answers 111 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Herbert
Top achievements
Rank 1
Herbert asked on 04 Sep 2012, 07:51 PM
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 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 06 Sep 2012, 12:41 PM
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!
0
Accepted
Alexander
Telerik team
answered on 25 Sep 2012, 04:20 PM
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!
Tags
Data Access Free Edition
Asked by
Herbert
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or