Performance improvements

Watch the Performance Improvements video on YouTube.

Batch updates and deletes

Updating and deleting are a major part of any application. LINQ to SQL takes a lot of work to update or delete an entity, and it can't update or delete several entities at once.

To update or delete a single entity, LINQ to SQL first retrieves the entity from the database, so it takes two calls even when you already have the information you need. PLINQO sends updates and deletes directly, which removes the first call. Performance improves, and you write fewer lines of code.

Updating or deleting many entities is a weak spot of most ORMs, LINQ to SQL included: they issue one statement per entity, when a single SQL statement would do the job much more efficiently. PLINQO updates and deletes many entities at once, based on a filter.

Delete

//Manager classes delete method
context.Manager.User.Delete(1);
//Query extension delete method
context.User.Delete(1);

//works for managers and queries
context.User.Delete(u => u.FirstName == "firstname");

Update

context.Task.Update(t => t.StatusId == 1, t2 => new Task {StatusId = 2});

IQueryable<User> users = context.User.Where(u => u.FirstName == "firstname");
context.User.Update(users, u => new User {FirstName = "newfirstname"});

You don't call SubmitChanges(): the updates and deletes run immediately.

Stored procedures with multiple result sets

Sometimes it's more efficient to batch queries into one stored procedure to reduce the number of round trips to the database. When PLINQO generates your code, it recognizes the stored procedures that return multiple result sets and gives you an easy way to handle the results.

For example, this stored procedure returns two result sets:

Create Procedure [dbo].[ReturnMultiplResultSets]
As
Select * From [User]
Select * From [Task]

This is how you read them with PLINQO:

IMultipleResults results = context.ReturnMultiplResultSets();
List<User> users = results.GetResult<User>().ToList();
List<Task> tasks = results.GetResult<Task>().ToList();

Batch queries

When you buy three games at a store, you don't make three trips: you buy them all at once. Yet LINQ to SQL makes one trip to the database for each query. PLINQO batches queries, which can greatly reduce the time an operation takes. Use the ExecuteQuery method on the data context. This example runs Select * From User and Select * From Task in one trip to the database:

var q1 = from u in context.User select u;
var q2 = from t in context.Task select t;
IMultipleResults results = context.ExecuteQuery(q1, q2);
List<User> users = results.GetResult<User>().ToList();
List<Task> tasks = results.GetResult<Task>().ToList();

For another way to batch queries, see Future queries. PLINQO also makes entities easy to serialize; see Entity enhancements.