且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有更新,删除,插入的LINQ-to-SQL CompiledQuery.Compile()?

更新时间:2023-01-20 21:43:27

有很大的不同. Linq-To-SQL选择查询可以是大型的复杂表达式树.这些可能需要一段时间才能进行编译".在这种情况下,可以合并到可以在SQL Server上运行的某些T-SQL.因此,缓存操作的结果以便可以重复使用是很有意义的.

There is a big difference. Linq-To-SQL select queries can be large complex expressions trees. Its these that may take sometime 'compiling'. In this case coalescing to some T-SQL that can be run against a SQL Server. So it makes sense to cache the result of an operation so that it can be re-used.

但是,其他Delete,Update和Insert是简单的操作,不需要将表达式树转换为T-SQL(LINQ本身就是关于查询的).不幸的是,我们已经受过培训,可以将执行这些其他操作的SQL代码视为查询",而实际上并不需要任何信息.

However other Delete, Update, and Insert are simple operations that do not require an expression tree to be converted to T-SQL (LINQ itself is all about querying). Its just unfortunate that we've been trained to think of SQL code that performs these other operations as 'queries', we're not actuall asking for any info.

这些操作仅由DataContext定义,而不由LINQ定义,因此执行这些功能的代码已经编译.

These operations are only defined by the DataContext not by LINQ hence the code to perform these functions is already compiled.