.net Enum 支持实体框架数据库优先
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17731557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enum Support for Entity Framework Database First
提问by TMan
I can find a bunch of tutorials on how to implement enum support for model first and code first like these:
我可以找到一堆关于如何首先实现对模型和代码的枚举支持的教程,如下所示:
http://msdn.microsoft.com/en-us/data/jj248772.aspx
http://msdn.microsoft.com/en-us/data/jj248772.aspx
http://msdn.microsoft.com/en-us/data/hh859576.aspx
http://msdn.microsoft.com/en-us/data/hh859576.aspx
Can anyone explain to me or provide me with some instructions on how to properly implement enum support for database first applications. I'd imagine I'd have to start in the edmx designer and right click one of my columns in the tables and convert to enum? Thanks for any advice. I'm using .NET 4.5 and Enity Framework 5.0
任何人都可以向我解释或向我提供有关如何正确实现对数据库优先应用程序的枚举支持的一些说明。我想我必须从 edmx 设计器开始,然后右键单击表中的一列并转换为枚举?感谢您的任何建议。我正在使用 .NET 4.5 和 Enity Framework 5.0
采纳答案by TMan
What I wound up doing is changing the column type to int in the database then I went into the edmx and updated model from database, then I went and added a enum type and then changed the column type in the edmx designer to be of type of that enum. Reupdated the poco's and everything Works good!
我最终做的是将数据库中的列类型更改为 int 然后我进入 edmx 并从数据库更新模型,然后我添加了一个枚举类型,然后将 edmx 设计器中的列类型更改为类型那个枚举。重新更新了 poco,一切正常!
回答by David Sarmiento
You should probably read thisas well.
您可能也应该阅读本文。
Enum Types are not created in your model via Database-First actions
- When you create an EDM from an existing database, Enums are not defined in your model.
- Update Model from Database will preserve your declaration of Enum types, but again, will not detect Enum constructs from your database.
枚举类型不是通过数据库优先操作在您的模型中创建的
- 从现有数据库创建 EDM 时,模型中未定义 Enum。
- 从数据库更新模型将保留您对 Enum 类型的声明,但同样不会从您的数据库中检测 Enum 构造。
I've seen a couple of solutionsthat use T4, but in my specific case its just adding unneeded complexity to my project. So I will give in and so the enums code-first.
我见过 几个使用 T4的解决方案,但在我的特定情况下,它只是给我的项目增加了不必要的复杂性。所以我会放弃,所以枚举代码优先。
回答by mostruash
Here is my wild guess: After you generate your .edmx file from your database, you can follow the guide in the following link: http://msdn.microsoft.com/en-us/data/jj248772.aspx
这是我的疯狂猜测:从数据库生成 .edmx 文件后,您可以按照以下链接中的指南进行操作:http: //msdn.microsoft.com/en-us/data/jj248772.aspx

