PLINQO adds missing features to LINQ to SQL
Sunday, January 24, 2010 6:14:27 AM
While the LINQ to SQL technology is amazing it does have some missing features.
That is until now.... Take a look at PLINQO ( http://plinqo.com/ )
Comparison Operators
db.User.ByAge(21, CodeSmith.Data.Linq.ComparisonOperator.GreaterThan);
Detach
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();
}
Clone
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
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);
Query Result Cache
//query is cached using the default settings
var tasks = context.Task.ByAssignedId(UserId).FromCache();
//query result is now cached 300 seconds
var approvedUsers = context.User.ByIsApproved(true).FromCache(300);
Cache Manager
CacheManager.Set("user-17", user, CacheSettings.FromDuration(30));
User user = CacheManager.Get<User>("user-17");
CacheManager.Remove("user-17");
Many to Many Relationships
Auditing
Rules Engine
A rule for the minimum length of UserName is added.
static partial void AddSharedRules()
{
RuleManager.AddShared<User>(new CustomRule<string>("UserName", "UserName must be 5 characters.", MinLengthUserName));
}
private static bool MinLengthUserName(string username)
{
if (String.IsNullOrEmpty(username) || username.Length < 5)
return false;
else
return true;
}
When any rules are broken, no data is updated and a nice list of the rules broken is returned.
using (var context = new TrackerDataContext())
{
User user = new User();
context.User.InsertOnSubmit(user);
context.SubmitChanges();
}
Performance Improvements
Batch Updates and Deletes
Stored Procedures with multiple result sets
Future Queries
Here is a quick sample.
// build up multiple queries
var q1 = db.User
.ByEmailAddress("<a class="linkification-ext" href="mailto:one@test.com" title="Linkification: mailto:one@test.com">one@test.com</a>")
.Future();
var q2 = db.Task
.Where(t => t.Summary == "Test")
.Future();
// this triggers the loading of all the future queries
var users = q1.ToList();
No data is retrieved until q1.ToList(); is executed. At that time, PLINQO knows to execute all the future queries automatically. The data is both batched and not retrieved until it is needed.
Not only can you queue up execution of queries for the future, the results can be cached as well. Again, PLINQO makes things easy. Here's a quick look at FutureCache.
// cache these results for 120 seconds
var q1 = db.User
.ByEmailAddress("<a class="linkification-ext" href="mailto:one@test.com" title="Linkification: mailto:one@test.com">one@test.com</a>")
.FutureCache(120);
var q2 = db.Task
.Where(t => t.Summary == "Test")
.FutureCache(120);
// this triggers the loading of all the future queries
var users = q1.ToList();
Linq to SQL Profiler
The list goes on and on and on...
If your serious about LINQ to SQL you really need to take a look at PLINQO... Its amazing.
Copyright 2008 CastleSoft