可插入的DbContext? [英] Pluggable DbContext?
问题描述
你好
我想做什么:
我 想要 外包 我的 实体 和
相关 制图 一个单独的 汇编 。 我的 " 上下文 经理 " 获取
汇编 pa th 作为参数 和 加载
配置 和 实体 as DbSet 对象
run 时间 。
了Exa mple ( 示范 类
名称 ) : < br $> b $ b $
汇编 :
Entity.Core.dll
包含 :
" IPluggableModule " 界面 必须 已实施 全部 模块
" 核心 背景 manger " - 我的 拥有 context 经理 。
: : - : : " CoreContextManager.LoadModule ( IPluggableModule < span title ="Zur AnzeigealternativerÜbersetzungenklicken">模块 ) - 用于的
方法 attach < span title ="Zur AnzeigealternativerÜbersetzungenklicken"> a 模块 to to 核心 上下文 经理 。
:: - :: " CoreContextManager.GetSet < T> ( )
装配1 : Entity.Address.dll ( 包含s 制图 和 实体 型号 和
实施 IPluggableModule 。
汇编 2: Entity.Order.dll ( 包含 制图 和 实体 型号 和
实施 IPluggableModule 。
Assembly 3 : Entity.Docu ment.dll ( 包含 制图 和 实体 型号 和
实施 IPluggableModule 。
汇编 - n ....
$ b 关注 这种模式, 我 可以 延伸 我的 申请 实施
of new assembly 。
如何 我 可以做到这一点  ;
实体 框架 CTP 5 < span title ="Zur AnzeigealternativerÜbersetzungenklicken">?
I want to outsource my entity and the
associated mapping in a separate assembly. my"context manager" gets the
assembly path as a parameter and loads
the configuration and entity as DbSet object at
run time.
Example (exemplary class
names):
Assembly:
Entity.Core.dll
contains:
"IPluggableModule" - Interface must be implemented by all modules
"core context manger" - my own context manager.
:: -:: "CoreContextManager.LoadModule (IPluggableModule module) - the
method used to attach a module to core context manager.
::--:: "CoreContextManager.GetSet <T> ()
Assembly 1: Entity.Address.dll (Contains mapping and entity model and an
implementation of IPluggableModule.
Assembly 2: Entity.Order.dll (Contains mapping and entity model and an
implementation of IPluggableModule.
Assembly 3: Entity.Document.dll (Contains mapping and entity model and an
implementation of IPluggableModule.
Assembly - n ....
Following this pattern, I can extend my application with the implementation
of new assemblies.
How I can do that with the
Entity Framework CTP 5?
谢谢你,对不起我的英语不好。
  ;
: - )
推荐答案
在开始使用模型进行数据访问之前,上下文需要知道模型中的所有实体.FilteModule方法只需将配置添加到临时挂起配置列表,然后覆盖
上的OnModelCreating方法,从临时存储中读取您的上下文。当然,一旦创建了模型,您将无法再添加任何配置。如果您需要模型要改变然后你需要抛弃上下文并在每次
模型改变时创建一个新上下文。
The context needs to be aware of all the entities in the model before you start using it for data access. The LoadModule method could just add the configuration to a temporary list of pending configuration and then override the OnModelCreating method on your context to read from the temporary store. Of course once the model has been created you won't be able to add any more configuration. If you need the model to change then you would need to throw away the context and create a new one each time the model changes.
~Rowan
这篇关于可插入的DbContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!