EntityFramework in parallel

c# entity-framework parallel-processing

Question

Is it feasible to make portions of the entity foundation for the following example function in parallel?

using (var dbContext = new DB())
{
var res = (from c in dbContext.Customers
           orderby c.Name
           select new
                    {
                    c.Id, 
                    c.Name,
                    c.Role
                    }
          ).ToDictionary(c => c.Id,
                         c => new Dictionary<string, object> {
                                                               { "Name",c.Name },
                                                               { "Role", c.Role }
                                                             });
}

What will change, for instance, if I add AsParrallel?

using (var dbContext = new DB())
{
var res = (from c in dbContext.Customers
           orderby c.Name
           select new
                    {
                    c.Id, 
                    c.Name,
                    c.Role
                    }
          ).AsParallel().ToDictionary(c => c.Id,
                         c => new Dictionary<string, object> {
                                                               { "Name",c.Name },
                                                               { "Role", c.Role }
                                                             });
}

And one more illustration. What are the distinctions between the three cases is the same question.

using (var dbContext = new DB()) 
{ 
var res = (from c in dbContext.Customers.AsParallel() 
           orderby c.Name 
           select new 
                    { 
                    c.Id,  
                    c.Name, 
                    c.Role 
                   } 
          ).AsParallel().ToDictionary(c => c.Id, 
                         c => new Dictionary<string, object> { 
                                                               { "Name",c.Name }, 
                                                               { "Role", c.Role } 
                                                             }); 
} 
1
3
4/28/2010 12:07:50 PM

Accepted Answer

No, the database handles the query, not the client. You cannot mix server-side processing with client-side Parallel Extensions. The database may perform the query using many threads to speed up the operation.

9
4/28/2010 11:18:36 AM

Popular Answer

Using PLINQ, you may (Parallel LINQ)

http://msdn.microsoft.com/en-us/library/dd460688.aspx

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

For instance (from the above):

IEnumerable data = ...; var q = data.AsParallel().Where(x => p(x)).Orderby(x => k(x)).Select(x => f(x));

foreach (var e in q) a(e);

You may also consider utilizing the TPL (Task Parallel Library) version for the research.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow