Shazoo
Shazoo

Reputation: 775

Entity Framework Code First table naming issue, singular confilcts with Plural

I have 2 table which I'm trying to access in MVC, one called Employees and one called Accountable. This is my code: -

public class dbEntity: DbContext
{
public dbEntity(): base("name=dbEntity") {}
public DbSet<Accountable> Accountable { get; set; }
public DbSet<Employees> Employees { get; set; }
}

The problem is the code complains that it can't find the table 'Accountables', I know I can add this line: -

protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } 

But then the code complains that it can't find 'Employee'. At the moment it is not practical to rename the tables, is there another way around it?

Thanks

Upvotes: 0

Views: 1294

Answers (1)

mituw16
mituw16

Reputation: 5250

Add a data annotation of your table's name in the database to your context class.

[Table("TableName")]

Upvotes: 5

Related Questions