Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I came across a bottleneck while testing an application that interfaces with a SQL-Compact 3.5 database with EF.

Usually, when I come across a bottleneck like this, I rework the linq query to reduce the number of linq queries done because re-running the same linq query a dozen times on a database filled with thousands of entries creates a bit of overhead. Then, I use plinq to speed up instantiation time.

Doing this has worked fairly well until I tried to do this with the ShapeEntities table.

The ShapeEntity is an abstract entity which works as the base class for other entities that are nearly identical to each-other. I can't run this with the AsParallel() method.

C#
HashSet<Guid> keys ...

var x = 
    from shape in model.ShapeEntities.AsParallel()
    where keys.Contains(shape.ImageKey)
    select shape;

List<ShapeEntity> shapes = new List<ShapeEntity>(x);


If I were to remove the AsParallel() from the code above, the query takes about 1.4 seconds to execute when we put it in the list. With the AsParallel() method, I get an AccessViolationException after about 40 seconds. It never gets past instantiation.

Does anyone have any ideas on how to speed this up? I can't do ImageEntity.ShapeEntities because then it turns into 1.2 seconds per ImageEntity.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900