My code is giving me an EntityCommandExecutionException when i’m trying getting data from my Bieren Table.
The exception message says that it can’t find “dbo.Biers” which is quite obvious because it’s called “dbo.Bieren”.
I can quite easily fix this by just renaming the table in the database. Altough i don’t like fixing my database around my code’s errors.
How can i make the entity framework use the correct table instead of changing the name of my table?
Thanks in advance.
For the database-first approach, StriplingWarrior’s solution works well. But if you use the code-first approach, you could use
System.ComponentModel.DataAnnotations.TableAttributeon a target entity class to map an entity class to a database table.However, this way is slightly annoying, because we commonly want to define a pure entity class. To do this, you could entrust it to another class or use the overrided
OnModelCreatingmethod in theDbContextclass as the following.