EF Error while retrieving data: invalid table name in SQL

I have a simple edmx with two tables. Tables are linked by one Navigation Property . (1 to many).

When I run my code, I get the Exception: "Invalid dbo.Enquiries object name"

There is no dbo.Enquiries in the dbo.Enquiries (actually called dbo.Enquiry ), so the error itself explains it. But where does he find this name and how to fix it?

Edited to display code on request.

  var foo = (from d in context.Dealerships join e in context.Enquiry on d.Id equals e.DealershipId where (d.ParentBusinessId == id) select d).AsEnumerable(); 

Here is the sql created.

  foo {SELECT [Extent1].[Id] AS [Id], [Extent1].[BusinessName] AS [BusinessName] FROM [dbo].[Dealerships] AS [Extent1] INNER JOIN [dbo].[Enquiries] AS [Extent2] ON [Extent1].[Id] = [Extent2].[DealershipId] WHERE [Extent1].[ParentBusinessId] = @p__linq__0} 

But for life, I can’t see where / how he decides to change the name. Request for internal join requests.

+4
source share
4 answers

Answer found. Pluralism is only on modeling. I had to explicitly tell my DbContext not to use the Pluralise names (I dare not rename this database, so Im adhered to the strange convention that was used.)

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

Try deleting the table from edmx and after updating the model.

0
source

It seems that you are using model-based development. If so, then you seem to have made some changes to the model but not reflected them in the database.

Use the option to generate a database from the model, and it will synchronize the database with the model.

0
source

Try closing the graphical representation for the EF model. Right-click and open in the XML editor. The mapping to the table should be there, and you can fix it. OR If you have changed the mode since import / update, you can completely delete the model and import the model again.
The code that accessed the model should still be fine.

0
source

All Articles