Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First: "The specified table 'foo' was not found in the model."

Haven't seen this error before, and a cursory web search turns up very little. Here's (I think) the offending code:

this.HasMany(a => a.ListItems).WithRequired()
    .Map(m =>
        {
            m.MapKey("AttributeId");
            m.ToTable("ProductAttributeListItem");
        }
    )
;

And here's the full error:

The specified table 'ProductAttributeListItem' was not found in the model. Ensure that the table name has been correctly specified.

The table is there and spelled correctly.

The lack of search results makes me think I'm missing something obvious. What might that be?

like image 822
Josh Schultz Avatar asked Nov 24 '25 17:11

Josh Schultz


1 Answers

If you want to define the table name of the entity ListItems is refering to you need to do that on the entity, not in the relationship mapping:

modelBuilder.Entity<ListItem>() // or whatever the entity is called
    .ToTable("ProductAttributeListItem");

And remove m.ToTable from the Map action.

like image 115
Slauma Avatar answered Nov 28 '25 17:11

Slauma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!