简体   繁体   English

在Windows Phone上使用Linq to SQL时,是否可以提高批量删除的性能?

[英]Is it possible to improve the performance of batch deletions when using Linq to SQL on Windows Phone?

I'm using Linq-to-SQL in a Windows Phone application to act as a cache when out of network/Wi-Fi coverage. 我在Windows Phone应用程序中使用Linq-to-SQL在网络/ Wi-Fi覆盖范围外时充当缓存。 This all works great, but I've found that removing stale entries from the cache appears to use a lot of separate of separate statements. 这一切都很好,但我发现从缓存中删除过时的条目似乎使用了大量单独的单独语句。

Considering the (relatively trivial) case to clear a table (for example, if the end user chooses to log out): 考虑清除表的(相对简单的)情况(例如,如果最终用户选择注销):

context.CacheChecks.DeleteAllOnSubmit(context.CacheChecks);

You'd hope that the generated SQL would be of the form (or something equivelant): 希望生成的SQL是形式(或equivelant):

DELETE FROM CacheChecks

However it turns into something more akin to: 然而,它变成了更类似于:

SELECT [t0].[LastChecked], [t0].[EntityType]
FROM [CacheChecks] AS [t0]
-- @p0: Input DateTime
-- (Size = 0; Prec = 0; Scale = 0) [3/13/2008 12:00:00 AM]

DELETE FROM [CacheChecks] WHERE [EntityType] = @p0
-- @p0: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [{GUID}]

DELETE FROM [CacheChecks] WHERE [EntityType] = @p0
-- @p0: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [{GUID}]

-- Individual DELETE statements for each row

When on the desktop, I've seen various extension methods to allow for batch updates, which seem to be based on this article by Terry Aney , but this approach doesn't work in the windows Phone world, as there is no way to create an arbitary DbCommand for a given context. 在桌面上,我已经看到了各种扩展方法,允许批量更新,这似乎是基于Terry Aney的这篇文章 ,但这种方法在windows Phone世界中不起作用,因为没有办法创建给定上下文的仲裁DbCommand

Is there another way to handle a batch deletion of many rows (1,000s) in a more efficient manner than row by row? 是否有另一种方法可以以比行逐行更有效的方式处理多行(1,000s)的批量删除?

Yes, it is possible to perform deletes that bypass the Query processor, in my test improving time to delete 100 rows from 320 ms to 70 ms. 是的,可以在我的测试中执行绕过查询处理器的删除操作,从而缩短从320毫秒到70毫秒的100行删除时间。 You can do so by simply adding a rowversion column to your table: 您只需在表中添加rowversion列即可:

[Column(IsVersion=true)] 
private Binary _version;

More info here: http://erikej.blogspot.dk/2012/04/windows-phone-local-database-tip.html 更多信息: http//erikej.blogspot.dk/2012/04/windows-phone-local-database-tip.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM