使用EF代码优先 - 标准方法种子DB,然后使用? [英] Enums with EF code-first - standard method to seeding DB and then using?

查看:75
本文介绍了使用EF代码优先 - 标准方法种子DB,然后使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有使用枚举在EF代码优先的标准方法?似乎有一些使用枚举类的例子。



然而,我想要能够定义枚举,并且枚举值也被种子使用数据库初始化器进入数据库。在定义枚举并创建包装器时似乎没有太多的意义,如果我必须从枚举中手动种植数据库表。

解决方案

现在支持: http://blogs.msdn.com/b/adonet/archive/2011/06/30/announcing-the-microsoft-entity-framework-june-2011-ctp。 aspx


Microsoft Entity Framework 2011年6月CTP引入了新的运行时和设计时功能。以下是一些新的运行时功能:




  • 实体框架中现在可以使用枚举数据类型。您可以使用Visual Studio中的实体设计器来模拟具有枚举属性的实体,或者使用代码优先工作流来定义具有枚举对象作为属性的实体。您可以像任何其他标量属性一样使用您的枚举属性,例如LINQ查询和更新...



有几个新的Visual Studio中的实体框架设计器的功能:




  • 实体设计器现在支持创建枚举,空间数据类型和表值设计器功能 ...



Is there a standard way to using Enums in EF code-first? There seems to be some examples making use of a wrapper class for the enum.

However, I would like to be able to define the enum and have the enum values also seeded into the database using the database initializer. There doesn't seem to be much point in defining the enum and creating a wrapper, if I then have to seed the database table manually from the enum.

解决方案

Now supported : http://blogs.msdn.com/b/adonet/archive/2011/06/30/announcing-the-microsoft-entity-framework-june-2011-ctp.aspx

The Microsoft Entity Framework June 2011 CTP introduces both new runtime and design-time features. Here are some of the new runtime features:

  • The Enum data-type is now available in the Entity Framework. You can use either the Entity Designer within Visual Studio to model entities that have Enum properties, or use the Code First workflow to define entities that have Enum objects as properties. You can use your Enum property just like any other scalar property, such as in LINQ queries and updates...

There are several new features for the Entity Framework Designer within Visual Studio:

  • The Entity Designer now supports creation of Enums, spatial data-types and table-value functions from the designer surface...

这篇关于使用EF代码优先 - 标准方法种子DB,然后使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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