使用LinqToDatasets缓慢更新/插入SQL Server CE [英] Slow Update/insert into SQL Server CE using LinqToDatasets

查看:94
本文介绍了使用LinqToDatasets缓慢更新/插入SQL Server CE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用LinqToDatasets更新/插入SQL Server CE 3.5文件的移动应用程序.

I have a mobile app that is using LinqToDatasets to update/insert into a SQL Server CE 3.5 File.

我的代码如下:

// All the MyClass Updates
MyTableAdapter myTableAdapter = new MyTableAdapter();

foreach (MyClassToInsert myClass in updates.MyClassChanges)
{
    // Update the row if it is already there
    int result = myTableAdapter.Update(myClass.FirstColumn, 
                                       myClass.SecondColumn, 
                                       myClass.FirstColumn);
    // If the row was not there then insert it.
    if (result == 0)
    {
        myTableAdapter.Insert(myClass.FirstColumn, myClass.SecondColumn);
    }
}

此代码用于使手持数据库与服务器数据库保持同步.问题是,如果它是完整更新(例如第一次),则有很多更新(大约125个).这使得这段代码(以及更多的循环需要很长的时间(我有三个这样的循环,每个循环要花费30秒以上的时间).

This code is used to keep the hand held database in sync with the server database. Problem is if it is a full update (first time for example) there are a lot of updates (about 125). That makes this code (and more loops like it take a very long time (I have three such loops that take over 30 seconds each).

是否有更快或更好的方法来执行这样的更新/插入?

Is there a faster or better way to do updates/inserts like this?

(我确实看到了这个 Codeplex项目,但是我看不到如何使两者兼容更新和插入.)

(I did see this Codeplex Project, but I could not see how to make it work with both updates and inserts.)

推荐答案

您应始终使用SqlCeResultSet在移动设备上进行数据访问,以实现最佳性能和内存使用率.您必须先确定要插入的数据,然后使用SqlCeBulkCopy示例之类的代码,并通过使用SqlCeResultSet的Seek和Update方法来使用类似的代码.

You should always use SqlCeResultSet for data access on mobile devices for maximum performance and memory usage. You must identify the data to be inserted and then use code like the SqlCeBulkCopy sample, and use similar code by using the Seek and Update methods of the SqlCeResultSet.

这篇关于使用LinqToDatasets缓慢更新/插入SQL Server CE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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