EF 4.1的DbContext Generattor - 将实体在不同的项目? [英] EF 4.1 DbContext Generattor - Put Entities in different project?

查看:143
本文介绍了EF 4.1的DbContext Generattor - 将实体在不同的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们的应用程序架构的一部分,我们想确定我们的功能层之间的界限。一个典型的应用解决方案,因此,将包含以下内容:

As a part of our application architecture, we like to define clear lines between our functional layers. A typical application solution, therefore, will contain:


  • 实体

  • 模型

  • 任务

  • 演示

  • 前端

  • Entity
  • Model
  • Task
  • Presenter
  • FrontEnd

这些最终成为完全不同的程序集。

These end up being completely distinct assemblies.

的实体/模型圈定做是为了保持数据库访问功能中从我们波苏斯一个单独的层,所以,只有任务在任何时候需要知道型号,在大家高达演示知道实体

The Entity/Model delineation is done to keep database access functionality in a separate layer from our POCOs, so that only Task ever need know about Model, while everyone up to Presenter knows about Entity

使用代码优先或流利的API时,这工作得很好 - 但由于缺乏支持在这些范式的存储过程,事实证明,EF 4.1下我的必须的使用EDMX模型。

This works well when using Code-First or Fluent-API - but due to the lack of support for SPROCs in those paradigms, it turns out that under EF 4.1 I must use EDMX models.

所以 - 我生成使用的DbContext生成波苏斯,但由此产生的阶级结束。型号下,而我可以强制其命名空间到.Entity相反,他们仍然居住在装配。型号,现在意味着.Presenter必须引用。型号才能到类,应该在.Entity。

So - I'm generating POCOs using a DbContext Generator, but the resulting classes end up under .Model, and while I can force their namespace into .Entity instead, they still live in the .Model assembly, which means now .Presenter must reference .Model to get to classes that should be in .Entity.

有没有办法强制或招EF其生成的输出转储到不同的项目?

Is there a way to force or trick EF to dump its generated output into a different Project?

推荐答案

当然。的DbContext发电机只是两个T4模板。您可以移动模板生成实体到其他项目。你只需要修改模板,以指向正确的EDMX文件。这是默认的:

Sure. DbContext Generator are just two T4 templates. You can move the template generating entities to other project. You just need to modify template to point to correct EDMX file. This is default:

string inputFile = @"Model.edmx";

您必须将其更改为相对地址到你的EDMX文件。这将是这样的:

You must change it to relative address to your EDMX file. It will be something like:

string inputFile = @"../Model/Model.edmx"

该模板将自动使用当前项目的默认命名空间为生成的实体,但你将不得不修改第二个模板的上下文中使用的新的命名空间,以便实体类型正确地从引用的程序解决。

The template will automatically use default namespace of current project for generated entities but you will have to modify the second template for context to use the new namespace so that entity types are correctly resolved from referenced assembly.

有在另一个项目中使用模板的小缺点 - 当你修改模型也不会自动更新。你必须始终使用的运行定制工具的从上下文菜单模板文件手动触发实体娱乐。

There is small disadvantage of using template in another project - it will not update automatically when you modify model. You must always trigger entity recreation manually by using Run custom tool from context menu on template file.

这篇关于EF 4.1的DbContext Generattor - 将实体在不同的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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