LINQ to Sitecore

Community based implementation of a LINQ to Sitecore provider.
To implement a complete LINQ provider and OR Mapper for the Sitecore CMS.

The aim is to improve the querying possibilities for Sitecore developers by providing the LINQ querying syntax, static typing and full intellisense.
The LINQ to Sitecore project aims to provide the same capabilities as the LINQ to SQL provider and tools implemented in the .NET framework.

Project Status

Startup - please join the project
Current code is an implementation example


The following example extracts all news items from the database which has a date shorter than 5 days ago and is in a news folder which is enabled:
from i in new SitecoreItem(db).OfType(INewsItem)
   where i.Date > DateTime.Now()-5
    and i.Parent().OfType(INewsFolder).IsEnabled = True
  select i;

In the example, the LINQ to Sitecore ORM has mapped the NewsItem template to the INewsItem interface and the NewsFolder template to the INewsFolder template.

Supported operations

(Excuse my poor wiki formatting skills)

# LINQ Sitecore Query Comment
1 var items = new SitecoreContext(db).Axis() /Axis::*
2 var items = new SitecoreItem(item).Axis() /item/path/Axis::* This could also be implemented as //{itemID}/Axis::*. We need to determine which is faster.
3 var items = new SitecoreDatabase(db).Axis(ItemName) Axis::ItemName
4 var items = new SitecoreDatabase(db).Axis().OfType<ITemplateType>() Axis::@@templateidTemplateID The ITemplateType must have an attached SitecoreTemplateAttribute which states the template ID. This should be implemented as Axis::@@TemplateIDTemplateID1 or @@TemplateIDTemplateID2 or @@TemplateIDTemplateID3 , … Where TemplateID1..x are templates which are derive from the template with the given TemplateID
5 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.Where(i => i.Field = Value) Axis::*FieldValue
6 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.Where(i => i.GetPropertyValue(Property) = Value) Axis::*@@PropertyValue
7 var ctx = new SitecoreDatabase(db).Axis<ITemplateType>(TemplateID) var items = ctx.Where(i => i.Field = Value) Axis::(@@templateidTemplateID) and (Field Value) Sitecore Query does not allow multiple predicates like @@templateid…@name”…”. Therefore we must include parenthesis.
8 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.Where(i => i.GetFieldValue(Field) = Value and i.GetFieldValue(Field2) = Value2] Axis::*FieldValue and Field2 Value2
9 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.First() Axis::*position() 1
10 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.ElementAt(index) Axis::*position() index 1
11 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.Take(count) Axis::*position() count 1
12 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.Skip(count) Axis::*position() count
13 var ctx = new SitecoreDatabase(db).Axis() var items = ctx.Union(new SitecoreDatabase(db).Axis()) Axis:: Axis::

Unsupported operations

These operations are not supported in Sitecore Query and will therefore not be supported in Sitecore to LINQ. Most operations can be accomplished by ordering the IEnumerable type returned, applying LINQ to Objects.

# LINQ Comment
1 OrderBy, ThenBy, Reverse
2 Join, GroupJoin
3 GroupBy
4 Concat
5 Intersect, Except
6 AsEnumerable, ToArray, ToList, ToDictionary, ToLookup, Cast
7 SequenceEqual
8 First(predicate) The First operator is only supported without predicate
9 FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault, ElementAtOrDefault, DefaultIfEmpty
10 Range, Repeat, Empty
11 Any, All, Contains
12 Count, LongCount, Sum, Min, Max, Average, Aggregate

Last edited Dec 15, 2008 at 8:40 PM by Eldblom, version 10