In EF Core 7.0, I have created the new table creation as like below and I see table in db also, but I'm seeing invalid object error when my code hit the logic.
I get this error:
SqlException: Invalid object name 'NewTableReqs'
DbContext
:
public DbSet<NewTableReq> NewTableReqs { get; set; }
Model.NewTableReq
implementation:
namespace Project.Models
{
public class NewTableReq
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int NewTableReqID { get; set; }
[Required]
public int FlagID { get; set; }
}
}
Couple of ideas to debug:
If you see the table, make sure there are not any misspellings.
Also double check your connection string - make sure that Initial Catalog
is set to database containing the NewTableReqs
.
Also, try running Add-Migration
to see what changes are between your context model and database model - maybe there is some difference between EF model and database?