Using LightSpeed-specific features from LINQ

LightSpeed 2 includes a LINQ provider that allows you to write queries against LightSpeed using the standard LINQ syntax, such as the following:

var query = from m in UnitOfWork.Members
            where m.UserName == "jb"
            select m;

However LightSpeed offers some features that the standard LINQ syntax doesn’t support. Specifically LightSpeed allows you to control, using named aggregates, when associations or large data objects are loaded, and it supports “soft deletion” including the retrieval of soft-deleted data.

The LightSpeed LINQ provider supports named aggregates via a special WithAggregate query operator. Here’s an example of how you would force a set of Contributions (from the LightSpeed samples) to load with the ContributionDetail named aggregate:

var query = from c in UnitOfWork.Contributions
            where c.Title.StartsWith("A")
            select c;
 
var contributions = query.WithAggregate("ContributionDetail").ToList();

This is equivalent to setting the AggregateName property on a LightSpeed Query object.

As for soft deletion, the soft delete functionality itself happens automatically at the LightSpeed engine level. The only extension is a way to include soft-deleted items in the LINQ query. This is done using the IncludeDeleted query operator:

var query = from a in UnitOfWork.Accounts
            select a;
 
var accounts = query.IncludeDeleted().ToList();

This is equivalent to setting the IncludeDeleted property on a LightSpeed Query object.

By using these two custom operators you can continue to access these LightSpeed features from within LINQ.

kick it on DotNetKicks.com

Tagged as LightSpeed

Leave a Reply

Archives

Join our mailer

You should join our newsletter! Sent monthly:

Back to Top