使用 Entity Framework 4 在运行时更改数据库架构的最佳实现是什么?

发布于 2024-09-09 16:55:20 字数 702 浏览 2 评论 0原文

我们正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-09-16 16:55:20

好吧,那么。对于未来的搜索者,我所实现的类似于 这个示例,尽管我加载了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文