We have an e-commerce site that uses Web Api and Entity Framework. I recently had created an ApiController for an entity called "BundleProduct". When I call the GET method on the controller, I get a System.Data.SqlClient.SqlException: "Invalid object name 'dbo.BundleProducts1'."
Using the VS debugger, this is the query that was being executed (there are only two columns in this table, with together form a primary key):
SELECT
[Extent1].[Fk_BundleID] AS [Fk_BundleID],
[Extent1].[Fk_ProductID] AS [Fk_ProductID]
FROM [dbo].[BundleProducts1] AS [Extent1]
There is no "BundleProducts1" table, it should be called "BundleProducts". I did a search in the code and cannot find any instances where the name "BundleProducts1" is used.
The BundleProducts table represents a many-to-many relationship between a "Bundles" table and "Products" table. This particular table has only two columns and both together are the primary key. I did look at the DbContext class and the only references it has to BundleProducts are:
public DbSet<BundleProduct> BundleProducts { get; set; }
modelBuilder.Entity<Bundle>()
.HasMany(e => e.Products)
.WithMany(e => e.Bundles)
.Map(m => m.ToTable("BundleProducts")
.MapLeftKey("Fk_BundleID")
.MapRightKey("Fk_ProductID"));
Why is EF appending a "1" to the table name and what can I do to change this?