user998416
user998416

Reputation: 21

How to control the generated model's name in Microsoft ADO.NET Entity Framework 4.1?

When I try to use Microsoft ADO.NET Entity Framework 4.1 in our project, I can not control the generated model's name.

For example, see the code first,

  public class Bank 
    { 
        [Key] 
        public Guid BankID { get; set; } 
        public string BankCardNumber { get; set; } 
        public string BankName { get; set; } 
    }    public class MyContext : DbContext 
    { 
        public DbSet<Bank> Banks { get; set; }  
    }    public class MyContextInitializer : DropCreateDatabaseIfModelChanges<MyContext> 
    { 
        protected override void Seed(MyContext context) 
        { 

        } 
    }

The code above is ok and it will be generated a table name called "Banks" in our database, but we want to control the generated table name, like "bank" or "opbanks", so could tell me how to do this?

Thank you very much.

Upvotes: 2

Views: 68

Answers (1)

Jeff Ogata
Jeff Ogata

Reputation: 57833

Try using the TableAttribute class. For reference, you can find a list of data annotations for EF 4.1 here.

Upvotes: 1

Related Questions