在实体框架中访问 MySql Timestamp 列时遇到问题

发布于 2024-11-11 14:33:58 字数 317 浏览 3 评论 0原文

我正在使用 MySql .net 连接器 6.3.6 和 Visual Studio 2008 sp1。 数据库中的一张表具有时间戳列。 当我生成实体映射(.edmx 文件)时,时间戳列将映射到 DateTimeOffset 数据类型。 当我在此表上执行 Linq 查询时,即使该列的表中存在有效的非空值,我总是会得到该列的 Null 值(该列可为空)。 如果我尝试将映射更新为日期时间数据类型,Visual Studio 会抛出错误。

我尝试用谷歌搜索可能的解决方案,很多地方都提到 MySql 时间戳列应该默认映射到 .net 日期时间数据类型。 我不确定问题是什么?

谢谢。

I am using MySql .net connector 6.3.6 and Visual Studio 2008 sp1.
One of the table in the database has a timestamp column.
When I generate Entity mappings (.edmx file), the timestamp column is getting mapped to DateTimeOffset data type.
And when I hit a Linq query on this table, I always get Null value for this column (this column is nullable) even though there are valid non-null values in the table for this column.
If I try to update the mapping to a datetime datatype, visual studio throws error.

I tried to google for possible solutions, and many places it was mentioned that MySql timestamp column should map to .net datetime datatype by default.
I am not sure what the problem is?

Thanks.

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

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

发布评论

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

评论(1

堇年纸鸢 2024-11-18 14:33:59

我建议您尝试 dotConnect for MySQL。它为相应的时间戳列生成日期时间属性。
您可以在此处下载试用版,该版本的唯一限制是 30-天试用期。

更新。您可以尝试使用 XML 编辑器编辑 .edmx 文件。将 CSDL 属性的类型设置为 DateTime,如果这会导致任何验证问题,您也可以尝试将 SSDL 属性的类型设置为“datetime”。

I recommend you to try dotConnect for MySQL. It generates DateTime properties for the corresponding Timestamp columns.
You can download a Trial version here, the only limitation of this version is 30-day trial period.

Update. You can try editing the .edmx file using an XML editor. Set the type of the CSDL property to DateTime, and if this causes any validation issues you can try setting the type of the SSDL property to "datetime" as well.

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