带有更新,删除,插入的LINQ-to-SQL CompiledQuery.Compile()? [英] LINQ-to-SQL CompiledQuery.Compile() with Update, Delete, Insert?

查看:84
本文介绍了带有更新,删除,插入的LINQ-to-SQL CompiledQuery.Compile()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

因此,我将LINQ-to-SQL中的所有选择查询都转换为使用CompiledQueries来加快处理速度.到目前为止,对于select语句效果很好,但是我还无法弄清楚如何预编译插入,更新或删除语句.

So I've got all my select queries in LINQ-to-SQL converted to using CompiledQueries to speed things up. Works great so far for select statements, but I haven't been able to figure out how to pre-compile insert, update, or delete statements.

当然,当您在LINQ-to-SQL中插入,删除或更新时,必须使用对象模型.但是很显然,它会在生成查询的过程中的某个地方进行预编译并将其存储在静态成员中.

Granted, when you're inserting, deleting or updating in LINQ-to-SQL, you have to use the object model. But obviously somewhere along the way it generates a query, which would be nice to pre-compile and store in a static member.

这可能吗?如果不进行预编译,LINQ的更新,删除和插入性能如何?我可以看到它比选择的要快得多,因为它们在下面执行的操作要简单得多,并且动态"要少得多.

Is this possible? What is LINQ performance like for updates, deletes and inserts when its not pre-compiled? I could see it being a lot faster than the selects, because what they do underneath is a lot simpler and less "dynamic"...

推荐答案

有很大的不同. 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.

这篇关于带有更新,删除,插入的LINQ-to-SQL CompiledQuery.Compile()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆