Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the ExecuteStoreCommand method in Entity Framework 5?

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.

like image 882
qakmak Avatar asked Dec 13 '12 09:12

qakmak


People also ask

What is ExecuteStoreCommand method?

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.

What is find method in database of Entity Framework?

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.

How do I run a raw query in EF core?

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.


1 Answers

Try this:

ctx.Database.ExecuteSqlCommand 
like image 200
Justin Harvey Avatar answered Sep 21 '22 17:09

Justin Harvey