简体   繁体   中英

entity framework use code first on single new schema in existing database

I have a new project I am starting and I would like to use entity framework 6 code first to handle the database portion. The problem is, I do not have permissions to create a new database on the server I need to use. Because of this, I would like to create a new schema in an existing database and then have entity framework only interact with that specific schema. There are many other tables in other schema in the database that are related to other projects (none of which make use of entity framework in any way) and entity framework needs to leave them alone when it is creating/dropping/modifying tables related to my project.

Is that possible? If so, how do I go about setting that up?

It turns out this is actually pretty easy using EF6! In your context just override OnModelCreating and add

modelBuilder.HasDefaultSchema("schema_name");

before the call to

base.OnModelCreating(modelBuilder);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM