使用 Entity Framework 4 在运行时更改数据库架构的最佳实现是什么?
我们正在 SQL Server 上构建一个 ASP.Net MVC 2 多租户应用程序,使用除其他地方讨论的“单一数据库、单独架构”模型 此处 和 此处,其中每个租户都有一个或多个用户,并使用其自己的、特定于租户的 SQL Server 架构进行划分。
该应用程序使用实体框架 4。为了让不同租户的用户访问其架构中的数据,我们需要能够在创建实体的 ObjectContext 时指定架构。
我看到了一些对此工具的引用(http://efmodeladapter.codeplex.com/)但是( 1) 我不想每次按照使用说明中指定生成 EDMX 时都更新代码,并且 (2) 它是在 EF4 之前生成的,所以我希望现在有一种更简单的方法。
那么,在 EF4 中执行此操作的最佳方法是什么?
谢谢
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.
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.
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.
So, what is the best way to do this in EF4?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,那么。对于未来的搜索者,我所实现的类似于 这个示例,尽管我加载了 ssdl、csdl 和 msl来自嵌入式资源,例如 此示例。
在实现中,我在 MVC 操作请求中创建存储库对象时,使用用户上下文来确定需要什么架构,使用前面提到的示例来编写架构并创建 EntityConnection,然后使用它创建我的 ObjectContext 实体。
它似乎运行得很好,尽管我有点担心它直观上看起来可能是一个性能问题。
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.
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.
It seems to function pretty well, though I am a bit concerned that it intuitively seems like it might be a performance problem.