I'm using EF5 in VS2012, and I trying to delete all data of some table using ExecuteStoreCommand
, something like this:
ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]");
but the problem is EF is telling me, method ExecuteStoreCommand not found. I can't understand why?
Can you tell me why?, or give me a performant solution remove all data of the table.
ExecuteStoreCommand(String, Object[]) Executes an arbitrary command directly against the data source using the existing connection. The command is specified using the server's native query language, such as SQL.
The Find method on DbSet uses the primary key value to attempt to find an entity tracked by the context. If the entity is not found in the context then a query will be sent to the database to find the entity there. Null is returned if the entity is not found in the context or in the database.
Basic raw SQL queries You can use the FromSqlRaw extension method to begin a LINQ query based on a raw SQL query. FromSqlRaw can only be used on query roots, that is directly on the DbSet<> . var blogs = context.
Try this:
ctx.Database.ExecuteSqlCommand
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With