C# 实体框架5中的ExecuteStoreCommand方法在哪里?
我在VS2012中使用EF5,我试图使用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
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”),但它不起作用。。。无法插入自定义主键。怎么做?