EF Code First CTP 5 - 从两个单独的程序集中的模型创建DbContext [英] EF Code First CTP 5 - Creating DbContext from models in two seperate assemblies

查看:63
本文介绍了EF Code First CTP 5 - 从两个单独的程序集中的模型创建DbContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始与CTP五合作,期待即将推出的项目MVC项目。以下是我想要的用例场景:



  • 在sperate 帮助程序集中创建一个抽象的DbContext - 这将有几个DbSet属性 旨在与TPT模型一起使用。 
  • 对于我的MVC网站,在继承基类的区域使用TPT模型。
  • 在MVC站点中创建一个 上下文,继承自帮助程序集中的抽象上下文。

所以,基本上我将模型分布在两个组件上。


当我运行测试时,我得到了"无法找到EntityType的映射和元数​​据信息...... "当模型处于拆分组件中时。如果我将所有模型移动到帮助程序集,一切正常。


请告知...



  • 如果这样目前是可行的,或者可以在发布时发布
  • 如果可能,请告知我需要做什么配置才能使这项工作

谢谢! 林恩


 


 

解决方案

我有找到了一个解决方案,我可以在派生的dbcontext类中为网站程序集中的模型添加DbSet,一切正常。我的继承链也是如此。尼斯 

I have started to work with CTP five in anticipation of an upcoming project MVC project. Here is the use case scenario I would like to have:

  • Create an abstract DbContext in a sperate helper assembly - this will have several DbSet properties  that are designed to be used with TPT models. 
  • For my MVC web site use TPT models in areas that inherit from bases classes.
  • Create a context in the MVC site, inheriting from the abstract context in the helper assembly.

So, basically I am having the models spread over two assemblies.

When I run tests I am getting "Mapping and metadata information could not be found for EntityType ... " when the models are in split assemblies. If I move all the models to the helper assembly everything works fine.

Please advise ...

  • if this is currently possible, or will be possible at release
  • if it is possible, please advise on what configuration I need to do to make this work

Thanks!  Lynn

 

 

解决方案

I have found a solution where by I can add a DbSet for the models in the web site assembly in the derived dbcontext class and everything works. Also my inheritance chain sticks. Nice. 


这篇关于EF Code First CTP 5 - 从两个单独的程序集中的模型创建DbContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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