简体   繁体   中英

Model-first Entity Framework - how to have multiple schemas

I googled/searched for an answer here in SO, but didn't find anything, specially specific for model-first approach.
I am just starting with creation of a new model for my new database and want to organize the entities for tables that logically belong to different scopes by having multiple schemas. I am using .NET-4.5

thanks in advance.

imagine that you have these two classes (Models):

public class Order
    {   
    }

 public class Book
    {

    }

now in entity framework code first, you can implement the table in schema like this:

public class ContextClass : DbContext
        {
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Entity<Order>().ToTable("Order", schemaName: "Orders");
                modelBuilder.Entity<Book>().ToTable("Book", schemaName: "Books");
            }
            public DbSet<Book> Customers { get; set; }
            public DbSet<Order> Orders { get; set; }
        }

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