2
我正在阅读一些在LinqToSQL中使用DataContect.ExecuteCommand
的代码。Linq DataContext.ExecuteCommand和SaveChanges
我主要关心的是这个ExecuteCommand
的变化发生在db上。一旦我拨打ExecuteCommand
或当我拨打SaveChanges
时,会发生吗?
我正在阅读一些在LinqToSQL中使用DataContect.ExecuteCommand
的代码。Linq DataContext.ExecuteCommand和SaveChanges
我主要关心的是这个ExecuteCommand
的变化发生在db上。一旦我拨打ExecuteCommand
或当我拨打SaveChanges
时,会发生吗?
只要你调用该方法,它将直接happend,并将对数据库执行命令,从文档的ExecuteCommand
:
直接执行SQL命令数据库。
为此你不应该ExecuteCommand
方法使用SaveChanges()
,因为ExecuteCommand
是要直接执行命令到数据库的情况下作为一种替代的SaveChanges()
。例如:
int result = DatabaseContext.ExecuteCommand("delete from blahblah = {0}", entity.Id));
谢谢。正是我需要知道的。 –