ASP.net 4.0实体数据模型的Mysql不把Mysql的右枚举 [英] ASP.net 4.0 Entity Data Model Mysql Not Treating Mysql Enums Right

查看:122
本文介绍了ASP.net 4.0实体数据模型的Mysql不把Mysql的右枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习,测试ADO.net实体数据模型与MySQL - 一切都很梦幻般的除了我已经注意到一件事。

I just starting learning, testing ADO.net Entity Data Models with MySql - everything is going fantastic except i've noticed one thing..

在我的MySQL表我创建了一个枚举列类型。当ASP.net创建模型类的枚举被视为字符串,而不是枚举 - 是有办法解决这个问题。

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?

在MySQL UserStatus列是有2个潜在特性枚举,Enabled和Disabled - 但是asp.net将其视作字符串值:
    user.UserStatus =已启用;

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";

希望看到这些方针的东西...
    user.UserStatus = UserStatuses.Enabled;

Was hoping to see something along these lines... user.UserStatus = UserStatuses.Enabled;

谢谢!

·罗兰

推荐答案

有没有这样的事,作为一个枚举SQL类型,至少不是一个标准的类型,这意味着它是非标准的,你就会有一个很难找到任何框架,正确支持正确。

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.

要更糟糕的是,实体框架目前不支持在code枚举类型无论是。还有一些黑客和变通方法,但你会发现他们是痛苦的,不值得。对于所有意图和目的,一个MySQL枚举是一个字符串对象。您可能需要发出一些自定义的SQL来获得枚举类型,虽然填充您的列表框。

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.

哦,供参考:的8个原因为什么MySQL的ENUM数据类型是邪恶

这篇关于ASP.net 4.0实体数据模型的Mysql不把Mysql的右枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆