A little LINQ to SharePoint with MatchPoint Expressions
Date: 05.10.2011
MatchPoint 3.0 comes with an expression extension that allows you to create simple CAML queries within MatchPoint expressions:
Web.Lists.Projects
.Where("Budget", ">", 1000000)
.Where("Status", "=", "Red")
.OrderBy("Budget")
This expression will be translated to the following CAML query:
<Query>
<Where>
<And>
<Eq>
<FieldRef Name="Budget">
<Value Type="Number">1000000</Value>
</Eq>
<Eq>
<FieldRef Name="Status">
<Value Type="Text">Red</Value>
</Eq>
</And>
</Where>
<OrderBy>
<FieldRef Name="Budget"></FieldRef>
</OrderBy>
</Query>
Let me show you what you can do with this expression extension with an example. There is a project management application. Each project is represented by a MatchPoint Workspace. The project itself is defined by a set of tasks that need to be worked off in order to complete the project. The project must not be closed unless all tasks are completed.
To enforce this constraint the Completed field on the Workspace Editor Web Part should remain hidden as long as there are open tasks in the list.
We add a VisibiltyCondition
to the Completed field. In the Expression
property of the configuration we need to return false
if there are any uncompleted tasks in the task list. This is where the CAML query expression extension comes handy:
!Web.Lists.Tasks.Where("Status", "!=", "Completed").Any()