Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Entity Enhancements

If you want some more info about detaching, cloning, and serialization, take a look at this quick overview!

Widget Connector
width500
urlhttp://www.youtube.com/watch?v=uP7dvVZpUUI&feature=player_embedded
height310

Detach

Inability to detach is what coders have complained about most when working with LINQ to SQL. Well, complain no more. PLINQO makes it easy to work with entities independent from a datacontext and attach to another when you are ready to save your changes. The following code is now possible thanks to PLINQO.

...

 

Code Block
languagecsharp
Task task = null;
using (var context = new TrackerDataContext())
{
    task = context.Task.FirstOrDefault(t => t.Id == 1);
    task.Detach();
}

task.StatusId = 1;

using (var context2 = new TrackerDataContext())
{
    context2.Task.Attach(task, true);
    context2.SubmitChanges();
}

...

The code shown here works without changes if your database supports row versioning. If row versioning is not supported in your database, the Update Check policy on each attribute in the dbml must be set to Never for detach to work.

...

PLINQO takes advantage of the DataContractSerializer in WCF to provide a quality cloning solution for all entity objects. Simply call the Clone method on any entity generated by PLINQO and what you get is an object copied to its own memory location. Below is a quick sample of the clone method in action. A user object is retrieved from the database, cloned, one property is changed, a new user is saved to the database.

...

Code Block
languagecsharp
using (var context = new TrackerDataContext())
{
    var u = context.Manager.User.GetByKey(1);
    User clonedUser = u.Clone();
    clonedUser.Id = 0;
    context.User.InsertOnSubmit(clonedUser);
    context.SubmitChanges();
}

...

 

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);

Next: Enum Generation