Entity Framework Structure Code First, configure the schema for the object

LINQ to SQL has a very simple convention to tell mapper which database schema to use - [Table(Name = "SchemaName.TableName")].

Is there something similar in EF CF 4.1? I would prefer not to use annotations in entity classes so that they are as clean as possible. For the sake of saving my project, I will sacrifice.

This question is close, but not quite what I need. It might even be deprecated, since it looks like it refers to classes that have been renamed or changed since the release of EF 4.1 - Entity Framework 4: Code First - Creating a db in another schema? MapSingleType?

EDIT: I should also mention that my application has three circuits at the moment, so I cannot use a solution that only modifies the standard circuit from "dbo" to "otherschema".

+5
source share
1 answer

The linked answer is old and it does not work because user agreements have been removed from the final version. If you want to change the name of the scheme, you can freely use the api:

public class Context : DbContext
{
    public DbSet<YourType> YourTypeSet { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<YourType>().ToTable("TableName", "SchemaName");
    }
}
+8
source

All Articles