如何使用EDMX文件的映射生成Entity Framework 6.x POCO类? [英] How to generate Entity Framework 6.x POCO classes with mappings from an EDMX file?

查看:152
本文介绍了如何使用EDMX文件的映射生成Entity Framework 6.x POCO类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将广泛的EDMX模型转换为POCO类。我需要从数据库第一种方法(EDMX与ObjectContext)到纯模型第一种方法(DbContext,没有EDMX文件)。我需要使用最新的Entity Framework稳定版本:6.1.1。

I'm in the process of converting an extensive EDMX model into POCO classes. I need to go from a Database First approach (EDMX with ObjectContext) to a pure Model First approach (DbContext with no EDMX file). I need to use the latest Entity Framework stable version: 6.1.1.

我已经测试了一些方法:

I've tested some approaches:


  • 添加 EF 6.x DbContext Generator 通过右键单击EDMX设计器中的空白处理代码生成项。这工作正常,但它不添加任何映射。使用这种方法,我仍然需要使用EDMX文件。它不是完整的代码优先。

  • 使用 EF 5。 x DbContext C#的流畅生成器。这会在设计时触发异常。我无法使用它。我不知道是不是因为我的VS实体框架工具已经更新到6.x.在评论中使用替代TT,这表明它与EF 6.0一起工作也没有帮助。

  • 使用 EntityFramework反向POCO生成器。这是最坏的,因为它不会考虑我的任何类和导航属性重命名。

  • 使用实体框架电动工具Beta 4 。再次,它只支持从数据库生成,而不是从EDMX文件生成。

  • Adding a the EF 6.x DbContext Generator code generation item by right-clicking the blank space in EDMX designer. This works fine, but it doesn't add any mappings. With this approach I have to still use the EDMX file. It's not full Code First.
  • Using the EF 5.x DbContext Fluent Generator for C#. This triggers an exception in design time. I'm not being able to use it. I don't know if that's because my VS Entity Framework tools are already updated to 6.x. Using the alternative TT in the comments, that suggests that it would work with EF 6.0 also doesn't help.
  • Using the EntityFramework Reverse POCO Generator. This is the worst because it won't consider any of my classes and navigation properties renames.
  • Using the Entity Framework Power Tools Beta 4. Again, it only supports generating from the database, not from the EDMX file.

我的要求:


  • 我需要输入为EDMX文件,而不是数据库。

  • 我需要输出为完整的Code First方法使用流畅的映射。

  • 我需要考虑在EDMX中定义的所有导航属性名称,否则会破坏大型代码库,甚至从ObjectContext迁移到DbContext将会中断。 / li>
  • I need the input to be the EDMX file, not the database.
  • I need the output to be a full Code First approach with Fluent mappings.
  • I need all my navigation property names defined in the EDMX to be considered because otherwise it would break a large codebase, even more then migrating from ObjectContext to DbContext will break.

你认为对我来说是个好选择?

What do you think would be a good option for me to go?

推荐答案

我遇到类似的情况,我使用了实体到DTO的生成器。
虽然它的目的是产生DTO,但我相信它可以帮助你的人。

I faced a similar case and I used Entities to DTO's generator. Although its purpose is to generate DTO's, however, I believe it can help someone in you case.

https://entitiestodtos.codeplex.com/

这篇关于如何使用EDMX文件的映射生成Entity Framework 6.x POCO类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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