ASP.net 4.0实体数据模型Mysql没有正确处理Mysql枚举
我刚刚开始学习,使用 MySql 测试 ADO.net 实体数据模型 - 一切都很顺利,除了我注意到一件事......
在我的 MySql 表中,我创建了一个 Enum 列类型。当 ASP.net 创建模型类时,枚举被视为字符串而不是枚举 - 有没有办法解决这个问题?
MySql 中的 UserStatus 列是一个 Enum,它有 2 个潜在属性:Enabled 和 Disabled - 然而 asp.net 将其视为字符串值: user.UserStatus = "已启用";
希望看到类似的东西...... user.UserStatus = UserStatuses.Enabled;
谢谢!!
罗伦
I just starting learning, testing ADO.net Entity Data Models with MySql - everything is going fantastic except i've noticed one thing..
In my MySql table i've created an Enum column type. When ASP.net creates the Model classes the enums are treated as strings and not as Enums - is there a way to fix this?
UserStatus column in MySql is an Enum that has 2 potential properties, Enabled and Disabled - however asp.net treats as string value:
user.UserStatus = "Enabled";
Was hoping to see something along these lines...
user.UserStatus = UserStatuses.Enabled;
Thanks!!
Loren
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在枚举 sql 类型这样的东西,至少不是标准类型,这意味着它是非标准的,您将很难找到任何正确支持它的框架。
更糟糕的是,实体框架当前也不支持代码中的 Enum 类型。有一些技巧和解决方法,但您会发现它们很痛苦且不值得。出于所有意图和目的,MySQL 枚举是一个字符串对象。不过,您可能需要发出一些自定义 sql 来获取枚举类型来填充列表框。
哦,仅供参考: MySQL 使用 ENUM 的 8 个原因数据类型是邪恶的
There's no such thing as an enum sql type, at least not a standard type, which means it's non-standard and you'll have a hard time finding any framework that properly supports it properly.
To make matters worse, Entity Framework does not currently support Enum types in code either. There are some hacks and workarounds, but you will find them to be painful and not worth it. For all intents and purposes, a MySQL enum is a string object. You may have to issue some custom sql to get the enum types to populate your listbox though.
Oh, and FYI: 8 Reasons why MySQL's ENUM data type is evil