Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架5中的ExecuteStoreCommand方法在哪里?_C#_Entity Framework_Visual Studio 2012_Entity Framework 5 - Fatal编程技术网

C# 实体框架5中的ExecuteStoreCommand方法在哪里?

C# 实体框架5中的ExecuteStoreCommand方法在哪里?,c#,entity-framework,visual-studio-2012,entity-framework-5,C#,Entity Framework,Visual Studio 2012,Entity Framework 5,我在VS2012中使用EF5,我试图使用ExecuteStoreCommand删除某个表的所有数据, 大概是这样的: ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]"); 但问题是EF告诉我,找不到ExecuteStoreCommand方法。我不明白为什么 您能告诉我原因吗?或者给我一个性能解决方案来删除表中的所有数据。试试以下方法: ctx.Database.ExecuteSqlCommand 你确定吗@tomfann

我在VS2012中使用EF5,我试图使用
ExecuteStoreCommand
删除某个表的所有数据, 大概是这样的:

ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]");
但问题是EF告诉我,找不到ExecuteStoreCommand方法。我不明白为什么

您能告诉我原因吗?或者给我一个性能解决方案来删除表中的所有数据。

试试以下方法:

ctx.Database.ExecuteSqlCommand

你确定吗@tomfanning,这取决于他使用的是ObjectContext还是DbContextCorrect。EF5/6默认为DbContext(POCO),除非您强制转换它们。此答案应标记为答案…这是一个完美的解决方案。我投票支持您@Justin Harveyi am使用:ctx.Database.ExecuteSqlCommand(“SET IDENTITY_INSERT profile ON”),但它不起作用。。。无法插入自定义主键。怎么做?