且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server“用户模式分离”和实体框架问题

更新时间:2022-11-04 17:33:02

我相信Codeplex上的实体框架运行时模型适配器库布兰登·海恩斯可能会解决你的问题。它将允许您在运行时更改模式名称。只要表的模式在每种情况下都相同,这应该相当简单。


I have been fooling around with EF with a database that has implemented user-schema separation with a twist, there are multiple tables with the same name but are separated via the schema.

So like:

admin.tasks
staff.tasks
contractor.tasks

When I created my EF model I noticed that there were 3 tasks tables:

tasks
tasks1
tasks2

Is this by design?

Also is there a way to tell EF to add the schema to the name of the entity or am I SOL and doing it myself?

I believe that the Entity Framework Runtime Model Adapter library on Codeplex from the mind of Brandon Haynes may solve your problem. It will allow you to change the schema name at runtime. As long as the schema of the table is the same in each case this should be fairly simple to implement.