Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

...

Code Block
languagecsharp
//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

...

Code Block
languagecsharp
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.

...

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

...

Code Block
languagesql
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.

...

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

...

 

It doesn't get any easier than this.

...

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.

...

Code Block
languagecsharp
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.

...

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

...

 

Deserialization is also made simple with PLINQO

...

Code Block
languagecsharp
task = Task.FromXml(xml);
task = Task.FromBinary(b);