我认为这是一个共同的问题,如果你必须管理你的同步。
The real problem is related to Linq To Sql, and the way it constructs DELETE statements.
因此,你有两个解决办法:
- override the default Linq To Sql DELETE behaviour (I do not suggest it): http://msdn.microsoft.com/en-us/library/bb882646.aspx
- use a ROWVERSION column in your table (more affordable as a solution), that helps Linq To Sql to manage large batch updates/deletes.
I will give you details about the second solution, much more easier to implement:
如果你在表格中用IsVersion属性一栏写成:
[Column(IsVersion = true)]
private Binary _version;
您将大大改进批量和定点性能。
BUT, BE CAREFUL!!!
If you use a ROWVERSION column in a table, you must remove any other Unique Index that involves your Primary Key, otherwise your app will crash without any exception thrown!!
This will be very annoying, believe me!!
See this example:
[Table(Name = "_customers")]
[Index(Columns = "Uid", IsUnique = true)] // <- THIS WILL GIVE YOU AN UNEXPECTED CRASH!
[Index(Columns = "Code", IsUnique = true)]
public class Customer : BaseModel, IBaseTable
{
[Column(IsVersion = true)]
private Binary _version;
[Column(IsPrimaryKey = true, IsDbGenerated = false, DbType = "UNIQUEIDENTIFIER NOT NULL", CanBeNull = false)]
public Guid Uid {...}
...
}
Just a few home-made statistics for my tables (I know that I do not show you the schema, but believe me: I have all foreign keys that you can imagine, and it works perfectly!)...
客户——和;从34492个ms到3230个ms(613个记录)
产品——和;从37233个ms到7264个ms(416个记录)
影印——和;从3713个ms到228个ms(2386个记录)
产品计量单位——和;从6 6347 ms到7321 ms(808 记录)