Dylan Czenski
Dylan Czenski

Reputation: 1365

Table attribute

I am creating a code-first model. What should my [Table] attribute be? [Table("PROGRAM_UNIT)"] or [Table("dbo.PROGRAM_UNIT")]?

Table property:

enter image description here

Table header in DBML:

enter image description here

Upvotes: 2

Views: 395

Answers (2)

tmg
tmg

Reputation: 20383

If you do not specify the schema name, EF will, by convention, use dbo.

For Entity Framework 6 and above, the schema can be changed for all tables by using the HasDefaultSchema method of DbModelBuilder:

public class CustomContext : DbContext
{
    ...    
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("MyDefaultDbSchema");
    }
}

To change the schema for a specific table you can use the Schema property of TableAttribute.

[Table("PROGRAM_UNIT", Schema = "schemaName")]

Upvotes: 2

Kahbazi
Kahbazi

Reputation: 14995

It should be [Table("PROGRAM_UNIT)"]

Upvotes: 1

Related Questions