I tries to delete an entity – table
This is the code:
db.Sessions.SqlQuery("delete table session");
db.SaveChanges();
This isnt delete the table. Or do anything..
db is inherits from DbContext object.
I’ve found a solution
foreach (var item in db.Sessions)
{
db.Sessions.Remove(item);
}
db.SaveChanges();
But I’m sure theres a better way.
Thanks.
SqlQueryas the name implies only for executing queries if you want to drop the table you need something else:With the use of the DbContext.Database property you can execute any DDL/DML query:
I have also created a repro and it’s working fine with EF4.3.1 with SQL Server2008:
Note: EF by default use plurar table names so you need to use sessions.