Sunday, 11 September 2011

LINQ SharePoint 2010 Projected Fields


A quick example of how to get Projected Fields using LINQ to SharePoint 2010

CAML - <Query>
<Where>
<And>
<BeginsWith>
<FieldRef Name="ContentTypeId" />
<Value Type="ContentTypeId">0x0100</Value>
</BeginsWith>
<Eq>
<FieldRef Name="ClientCity" />
<Value Type="Lookup">Chicago</Value>
</Eq>
</And>
</Where>
</Query>

<ViewFields>
<FieldRef Name="Title" />
<FieldRef Name="ClientTitle" />
<FieldRef Name="BudgetHours" />
</ViewFields>
<ProjectedFields>
<Field Name="ClientTitle" Type="Lookup"
List="Client" ShowField="Title" />
<Field Name="ClientCity" Type="Lookup"
List="Client" ShowField="City" />
</ProjectedFields>

<Joins>
<Join Type="LEFT" ListAlias="Client">
<!--List Name: Clients-->
<Eq>
<FieldRef Name="Client" RefType="ID" />
<FieldRef List="Client" Name="ID" />
</Eq>
</Join>
</Joins>

LINQ -
from p in data.Projects where
p.Client.City == "Chicago" select new
{
Name = p.Title,
ClientName = p.Client.Title,
Budget = p.BudgetHours
};

Ads by Google

No comments:

Post a Comment