LINQ to Entities 在 SQL 2005 Express 上生成包含 datetime2 的查询

发布于 2024-09-11 21:39:23 字数 835 浏览 3 评论 0原文

我有一个 LINQ to Entities 应用程序和一个数据库项目来管理面向 .NET 4.0 的 VS 2010 解决方案中的架构。实体模型目前是从数据库进行逆向工程的。其中一个表是用日期时间类型的列定义的。数据库项目配置为使用 SQL Server 2005 兼容模式,因此一切部署正常。

我刚刚遇到一个问题,通过实体框架的更新语句似乎使用 datetime2 而不是 datetime,这会导致异常,因为 SQL 2005 不支持该数据类型:

System.Data.UpdateException: An error occurred while updating the entries. 
See the inner exception for details. ---> System.ArgumentException: The version 
of SQL Server in use does not support datatype 'datetime2'.

从堆栈跟踪看来,错误似乎 我已经

System.Data.Mapping.Update.DynamicUpdateCommand

查看了所有 SQL 代码和实体代码,并确认不存在对 datetime2 的引用(包括 dbschema 文件)。我只能得出结论,该数据类型是在实体框架生成的动态SQL查询中生成的。

我如何确认或否认这一点,以及如何阻止它发生?实体框架不知道我已要求 db 项目以 2005 兼容模式为目标,并且我看不到一种方法来指出它正在查看的版本。无论如何,我在一台安装了 2008 Express 的机器上创建了这个项目,但我会定期切换到另一台没有安装(并且还无法升级)的机器。

I've got a LINQ to Entities app and a database project to manage the schema in a VS 2010 solution targetting .NET 4.0. The entity model is currently reverse engineered from the database. One of the tables is defined with a column of type datetime. The database project is configured to use SQL Server 2005 compatability mode and so it all deploys OK.

I've just run into an issue where an update statement via the entity framework appears to be using datetime2 rather than datetime, which causes an exception because SQL 2005 doesn't support that data type:

System.Data.UpdateException: An error occurred while updating the entries. 
See the inner exception for details. ---> System.ArgumentException: The version 
of SQL Server in use does not support datatype 'datetime2'.

From the stack trace is appears that the error seems to be occurring inside of:

System.Data.Mapping.Update.DynamicUpdateCommand

I've looked through all of my SQL code and entity code and confirmed that no references exist to datetime2 (including the dbschema file). I can only conclude that the data type is being generated in the dynamic SQL query generated by the entity framework.

How can I confirm or deny this, and how to I stop it from happening? Entity framework doesn't know that I have asked the db project to target 2005 compatability mode, and I can't see a way to point out to it the version that it's looking at. For what it's worth, I created this project on a machine that did have 2008 Express installed, but I periodically switch to another machine that doesn't (and can't upgrade just yet).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剧终人散尽 2024-09-18 21:39:23

您需要将 EDMX 内的 ProviderManifestToken 更改为值 2005。您可能是根据 2008 DB 生成的 DB。进行此更改后,EF 将停止使用 2008 语法。

You need to change the ProviderManifestToken inside your EDMX to the value 2005. You probably generated your DB against a 2008 DB. Make this change and the EF will stop using 2008 syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文