LINQ TO UMBRACO

LINQ to Umbraco was developed to provide developers with an alternative way to work with Umbraco content nodes. It was designed from the start to provide an alternative to XSLT for developers who prefer working in a more traditional .NET environment using POCOs (Plain Old CLR Object) and C# or VB.NET syntax. As such, it's important to note that it's not meant to be a replacement for the NodeFactory or Document API (discussed earlier in this chapter). The default data provider for LINQ to Umbraco is the NodeDataProvider, which looks directly at the XML cache, much like the XSLT templates do. So, using LINQ to Umbraco out of the box means that you have access to the published nodes in a strongly typed read-only fashion.

image If all you're trying to do is output a document type property on a page, then sticking with standard Umbraco display fields, namely the <umbraco:item /> tag that is covered in Chapter 4, is best.

Getting Started with LINQ to Umbraco

To use LINQ to Umbraco in your project, you must export your document types to .NET. The process of exporting your document types is covered in Chapter 3. Doing this provides you with several data contexts from which to query the nodes you're looking for. Listings 12-18 goes back to the FAQ example and shows how to output nodes using LINQ method or query syntax.

Before you can dig into code samples, export your document ...

Get Umbraco User's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.