简体   繁体   English

EF 4.1 Sql CE性能问题

[英]EF 4.1 Sql CE Performance problems

I know, i'm on question mode tonight, 我知道,我今晚处于提问模式,

I'm in the middle of building a desktop application. 我正在构建桌面应用程序。 Luckily for me a choose a open architecture because i ran into the following problem: 对我来说幸运的是选择一个开放式体系结构,因为我遇到了以下问题:

My application allows users to add operations. 我的应用程序允许用户添加操作。 In my tests, i only added small (test) operations which are easily manageble. 在我的测试中,我只添加了易于管理的小型(测试)操作。 Each operation is added to a datastore which currently is a SQL CE 4.0 database (accessed using EF 4.1 code first which is great). 每个操作都被添加到当前为SQL CE 4.0数据库的数据存储中(首先使用EF 4.1代码进行访问非常好)。

Now i tested the application using a common operation which is bigger (approximatly 4000 rows in the Database). 现在,我使用一个更大的通用操作(在数据库中大约4000行)测试了该应用程序。 Rather then taking a few seconds, it actually takes a few minutes for insert! 而不是花几秒钟,实际上要花费几分钟! In the big table, there is only 1 foreign key and ofcourse the primary key, but it seems 4000 rows are just to much for it. 在大表中,只有1个外键,当然还有主键,但是似乎4000行对它来说实在太多了。

All rows are inserted in 1 batch and the real performance lack is on the SaveChanges command. 所有的行都分批插入,而真正的性能不足是在SaveChanges命令上。

I've red about using manual queries (havent tested it) but this is no preferred option since transactions arent supported and it must be an isolated operation. 我已经对使用手动查询(已经对其进行了测试)感到不满,但这不是首选选项,因为它不支持事务处理并且它必须是一个独立的操作。

So, do i need a new strategy here? 那么,在这里我需要一种新的策略吗? On SQL Server 2008 you can do a bulk insert but appareantly that is also not supported by Sql Server CE. 在SQL Server 2008上,您可以进行批量插入,但是Sql Server CE也不支持。

What clientside solutions are as flexible as SQL Server CE and lightweight? 哪些客户端解决方案像SQL Server CE一样灵活且轻巧? (eg Ofcourse i dont want the user to install SQL Server, nor use some native components). (例如,我当然不希望用户安装SQL Server,也不要使用某些本机组件)。

I can use serialization in some forms but that feels like reinventing the wheel and is alot of work (upgrading, integrity, multithreaded access etc). 我可以以某种形式使用序列化,但是感觉就像是在重新发明轮子,而且工作量很大(升级,完整性,多线程访问等)。

Thanks in advance! 提前致谢!

The question is how slow is normally insert operation on SQL CE? 问题是在SQL CE上通常插入操作有多慢? The problem with EF is that it doesn't request one batch to insert 4.000 records but it inserts records one by one. EF的问题在于它不要求一批插入4.000条记录,而是一一插入记录。 Current EF version has no support for command batching so you are executing 4.000 inserts in the sequence. 当前的EF版本不支持命令批处理,因此您将按顺序执行4.000次插入。 This is a problem on a big SQL Server as well but it is usually faster. 在大型SQL Server上,这也是一个问题,但通常更快。 I was able to insert around 50.000 - 100.000 more complex records to SQL Server within six minutes on slower desktop and within three minutes on the server. 我能够在较慢的台式机上六分钟之内,在服务器上的三分钟之内,向SQL Server插入大约50.000-100.000个更复杂的记录。

http://msdn.microsoft.com/en-us/magazine/gg490349.aspx http://msdn.microsoft.com/en-us/magazine/gg490349.aspx

not specifically the anwser to your problem but these techniques will def help you troubleshoot your queries. 不是专门解决问题的方法,但是这些技术将帮助您解决查询问题。

Both answers were helpfull but didnt provide a solution. 这两个答案都很有帮助,但没有提供解决方案。

I found this: http://sqlcebulkcopy.codeplex.com/ which provides a SqlCeBulkCopy class which works and performed the insert within 2 seconds!. 我发现了这一点: http ://sqlcebulkcopy.codeplex.com/,它提供了一个SqlCeBulkCopy类,该类可以在2秒钟内工作并执行插入! I'm now working on intergrating it in my current repository and unitofwork model. 我现在正在将其集成到当前的存储库和unitofwork模型中。 As soon as i found the best solution i will post it here. 一旦找到最佳解决方案,我就会在这里发布。

Soon to be followed... 很快就会被...

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

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