我目前正在阅读一些在 LinqToSQL 中使用 DataContect.ExecuteCommand
的代码。
我主要关心的是这个ExecuteCommand
的更改何时发生在数据库上。当我调用 ExecuteCommand
或执行 SaveChanges
时,会立即发生这种情况吗?
最佳答案
一旦您调用该方法,它就会直接发生,并将针对数据库执行命令,来自 ExecuteCommand
的文档:
Executes SQL commands directly on the database.
因此,您不应将 SaveChanges()
与 ExecuteCommand
方法一起使用,因为 ExecuteCommand
用作 SaveChanges( )
如果您想直接对数据库执行命令。例如:
int result = DatabaseContext.ExecuteCommand("delete from blahblah = {0}", entity.Id));
关于c# - Linq DataContext.ExecuteCommand 和 SaveChanges,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33234266/