1. Skip to navigation
  2. Skip to content
  3. Skip to sidebar


PLINQO for LINQ to SQL

Performance Improvements

Batch updates and deletes

Deleting and updating are major parts of any application. PLINQO now provides an optimal solution whether working with one entity LINQ to SQL requires a lot of work to delete or update an entity and no support to delete or update multiple entities at one time. For single deletes, the object must be retrieved and populated in order to delete and update. Two calls to the database to delete or update an entity when you already have the information you need! PLINQO eliminates the first call by sending deletes and updates directly eliminating the need to do the extra work. Thus, performance is easily improved, plus time is saved with fewer lines of code.

Multiple updates and deletes are also a downside for most ORMs and LINQ to SQL is no different. When deleting or updating multiple entities without PLINQO, multiple statements are issued when a single SQL statement will get the job done a lot more efficiently. PLINQO offers the ability to create multiple updates and deletes based on a filter. Below is a look at the different features available for deleting and updating.

Deleting

	 
//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 users = context.User.Where(u => u.FirstName == "firstname");
context.User.Update(users, u => new User {FirstName = "newfirstname"});

As you can see, there is no need for SubmitChanges(). The actions are taken immediately and much better performance will be seen thanks to PLINQO's batch deleting and updating capabilities.

Stored Procedures with multiple result sets

There are times when it is more efficient to batch queries into one stored procedure in order to optimize the number of round trips to the database. During generation, PLINQO recognizes all stored procedures that return multiple results and provides a nice way to handle the results.

Here is a look at how this can be done. The following stored procedure is created.

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

Now we have a stored procedure returning multiple result sets and here is how PLINQO will handle it.

	 
IMultipleResults results = context.ReturnMultiplResultSets();
List users = results.GetResult().ToList();
List tasks = results.GetResult().ToList();

It doesn't get any easier than this.

Batch Queries

When heading to the video game store. money in hand, ready to purchase Call of Duty, Madden 10 and Tiger Woods 10, I am sure you do not make 3 trips to the store to buy the games, but take care of it in one purchase. Making three trips would would be incredibly inefficient. So why is this deemed acceptable by LINQ to SQL when pulling back data from the database. PLINQO finds this unacceptable! PLINQO supports batching queries making it possible to greatly optimize the time it takes completing operations. ExecuteQuery on the data context makes this possible. Here is an example that batches up Select * From User and Select * From Task into 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 users = results.GetResult().ToList();
List tasks = results.GetResult().ToList();

Easier Serialization

Serialization of entities has had developers running in circles from the early days of LINQ to SQL until now. PLINQO eliminates this frustration by eliminating the possibility of circular references and taking advantage of WCF datacontract serialization. Here is a sample of serializing an object using PLINQO.

	 
Task task = context.Task.GetByKey(1);
string xml = task.ToXml();
byte[] b = task.ToBinary();

Deserialization is also made simple with PLINQO

	 
task = Task.FromXml(xml);
task = Task.FromBinary(b);

Copyright © 2017 CodeSmith Tools, LLC. All rights reserved.