开发者

EntityFunctions.TruncateTime alternative when using EF CTP5 with Sql Server Compact Edition 4.0

开发者 https://www.devze.com 2023-02-12 10:14 出处:网络
I\'m using EF CTP5 code-first with Sql CE 4.0. I am trying to perform a time-insensitive date comparison between two DateTime properties.

I'm using EF CTP5 code-first with Sql CE 4.0. I am trying to perform a time-insensitive date comparison between two DateTime properties.

As linq to entites cannot parse the DateTime.Date property (which would have been nice) the solution is to use EntityFunctions.TruncateTime, however this doesn't appear to work with Sql CE 4.0.

I can manually compare the Year, Month and Day of the two dates, this works but makes the code a lot more verbose than it should be. Ideally I don't want to change my queries to use the long-hand version to make them work with both full sql server and sql ce 4.0.

Therefore does anyone have any clean and clever solutions to this? I think the solution w开发者_StackOverflow社区ill probably involve expression re-writing but I'm not quite sure where to start.

Any help is greatly appreciated,

Paul


Do you have the option of changing the structure of your database?

If so you could add an extra column with just the date part of the datetime, and then use that column in your query.

It will use a little more space in your database, but should run a little faster since you avoid any conversions.

0

精彩评论

暂无评论...
验证码 换一张
取 消