什么是改变在运行时使用实体框架4数据库架构的最佳执行? [英] What is the best implementation for changing the database schema at runtime using Entity Framework 4?

查看:109
本文介绍了什么是改变在运行时使用实体框架4数据库架构的最佳执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在建设使用单个数据库,独立模式在其他地方讨论的模式,SQL Server上的ASP.Net MVC 2多租户应用程序,的这里和<一个href=\"http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html\"相对=nofollow>这里,每个租户都有一个或多个用户,并分离出具有自身,特定于租户,SQL Server架构。

We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the "single database, separate schema" model discussed, among other places, here and here, where each tenant has one or more users and is split out with its own, tenant specific, SQL Server schema.

应用程序使用实体框架4.为了使用户对不同租户访问其架构中的数据,我们需要能够创造一个实体的ObjectContext时指定的模式。

The application is using Entity Framework 4. In order for users for different tenants to access the data in their schema, we need to be able to specify a schema when creating an entity's ObjectContext.

我已经看到了这个工具( HTTP几个引用://efmodeladapter.$c$cplex.com / ),但(1)我想不会有在使用指令规定;(2)它是产生之前EF4所以我希望有产生EDMX每次更新code现在是一个更简单的方法。

I have seen a few references to this tool (http://efmodeladapter.codeplex.com/) but (1) I would like to not have to update the code every time the EDMX is generated as specified in the Usage instruction and (2) it was produced before EF4 so I am hoping there is an easier way now.

那么,什么是EF4做到这一点的最好方法是什么?

So, what is the best way to do this in EF4?

感谢

推荐答案

那好吧。对于未来的搜索,我所实行的是类似<一个href=\"http://blogs.msdn.com/b/alexj/archive/2010/01/27/tip-51-how-to-load-ef-metadata-from-an-arbitrary-stream.aspx\"相对=nofollow>这个例子,虽然我加载SSDL,CSDL和MSL从像<一个嵌入的资源href=\"http://blogs.microsoft.co.il/blogs/idof/archive/2008/08/22/change-entity-framework-storage-db-schema-in-runtime.aspx\"相对=nofollow>这个例子的。

Well, ok then. For future searchers, what I have implemented is something like this example, though I load the ssdl, csdl, and msl from the embedded resources like this example.

在实现中,我创造了一个MVC操作请求一个资源库对象的时候,我把使用用户上下文来确定所需要的模式,可使用previously指出例子写的架构,并创建一个EntityConnection然后用它创建ObjectContext的我的实体。

In implementation, I when creating a repository object in an MVC action request, I take use a user context to determine what schema is needed, use the previously noted example to write the schema and create an EntityConnection and then use it create my ObjectContext entity.

这似乎功能pretty好,虽然我有点担心,它直观地看起来它可能是一个性能问题。

It seems to function pretty well, though I am a bit concerned that it intuitively seems like it might be a performance problem.

这篇关于什么是改变在运行时使用实体框架4数据库架构的最佳执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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