c# - Linq DataContext.ExecuteCommand 和 SaveChanges

标签 c# sql linq linq-to-sql

我目前正在阅读一些在 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/

相关文章:

mysql - 将 3 个表连接在一起

sql - 处理匿名用户和注册用户的正确方法

c# - 使用 Linq 查询区分

c# - 更改 LambdaExpression 中的参数名称只是为了显示

c# - 如果路径不是C:/Windows/Media,则无法播放声音

c# - 无法将类型 'int?[]' 隐式转换为 'int[]

sql - 更新外键值

asp.net - 如何缓存 IQueryable 对象?

Linq:计数大于值的情况

c# - 从匿名类型中获取值(value)?