I use Entity Framework Core in an ASP.NET C# project.
I have a table in the database called Sales
, and a view called HotSales
.
The view contains only the hot sales from the Sales
table + more info from another table using JOIN.
In the DbContext
class, I have a DbSet
object for each of them.
I try to delete a row from the Sales
table like this:
Sale sale = _context.Sales.FindAsync(id);
_context.Sales.Remove(sale as Sale);
_context.SaveChanges();
I get an error about HotSales
type:
The entity type ‘HotSales’ is not mapped to a table, therefore the entities cannot be persisted to the database. Call ‘ToTable’ in ‘OnModelCreating’ to map it to a table.
Why does Entity Framework Core recognizes the Sales
object as HotSales
? How can I delete the row?