What is the best implementation for changing the database schema at runtime using Entity Framework 4?

两盒软妹~` 提交于 2019-12-08 05:43:51

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3241232/what-is-the-best-implementation-for-changing-the-database-schema-at-runtime-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!