简体   繁体   English

Linq to SQL:使用Sql Server Compact Edition优化查询

[英]Linq to SQL : Optimizing queries with Sql Server Compact Edition

I've been using Linq to SQL against Sql Server CE. 我一直在使用Linq来针对Sql Server CE进行SQL。

Database is read only, so I can have several assumptions. 数据库是只读的,因此我可以有几个假设。

In order to refrain from accessing the file system, my initial approach was to cache needed entities to application memory and using linq to objects against them. 为了避免访问文件系统,我最初的方法是将所需的实体缓存到应用程序内存中,并使用linq来针对它们进行对象处理。

While it works well for limited queries, directly using Linq to SQL is superior than Linq to Objects when joins where needed. 尽管它对于有限的查询非常有效,但是在需要的地方进行连接时,直接使用Linq to SQL比使用Linq to Objects更好。

Back to starting point, I want to optimize my performances, my thought now is to enforce loading the entire file to the RAM, and using Linq to SQL against it. 回到起点,我想优化性能,现在我的想法是强制将整个文件加载到RAM,然后对它使用Linq to SQL。

Any thoughts of how do that? 有什么想法吗? Any more ideas? 还有其他想法吗?

Ariel 爱丽儿

It seems like your problem is sql index/foreign key performance vs. collection iterator performance. 看来您的问题是sql索引/外键性能与集合迭代器性能。

Linq to Datasets does offer a way to preserve relationships (more specifically, ADO.net Datasets have a relationship collection) and can enforce primary key, foreign key, and unique constraints. Linq to Datasets确实提供了一种保留关系的方法(更具体地说,ADO.net Datasets具有一个关系集合),并且可以强制执行主键,外键和唯一约束。 So, their join performance should be similar to Linq to SQL but will run in memory. 因此,它们的联接性能应类似于Linq to SQL,但将在内存中运行。

From my understanding of lite sql implementations, transactions can have a big impact on performance, so just starting your connection out with 根据我对lite sql实现的理解,事务可以对性能产生很大的影响,因此只需使用

BEGIN TRANSACTION

could have significant impact if you can leave the connection open for all of your queries. 如果您可以为所有查询打开连接,则可能会产生重大影响。 Benchmarking is probably the only sure way to answer this though. 基准测试可能是唯一可以解决此问题的方法。

Did you try Linq to DataSet ? 您是否尝试过Linq to DataSet

you can load everything in memory and you can use Linq query 您可以将所有内容加载到内存中,也可以使用Linq查询

I have no idea if the join will work like you want 我不知道该加入是否会如您所愿

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

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