我有两个简单的列表。一个是employee,它有1列Title。另一个是Company,它有1列Title。我在Employee List中添加了一个查找列,并将其指向Company List的ID。
现在我使用CSOM(没有javascript和没有服务器对象模型)编写这段代码
ClientContext c = new ClientContext(url);
List el = c.Web.Lists.GetByTitle("Employee");
CamlQuery query = new CamlQuery();
query.ViewXml = @"<View>
<ViewFields>
<FieldRef Name='ID'/>
<FieldRef Name='Title'/>
<FieldRef Name='CompanyTitle'/>
</ViewFields>
<Joins>
<Join Type='LEFT' ListAlias='Company'>
<Eq>
<FieldRef Name='Company' RefType='Id'/>
<FieldRef List='Company' Name='ID'/>
</Eq>
</Join>
</Joins>
<ProjectedFields>
<Field Name='CompanyTitle' Type='Lookup' List='Company' ShowField='Title'/>
</ProjectedFields>
<Query>
<Where>
<Eq>
<FieldRef Name='Company' LookupId='TRUE' />
<Value Type='Lookup'>10</Value>
</Eq>
</Where>
</Query>
</View>";
ListItemCollection items = el.GetItems(query);
c.Load(items);
c.ExecuteQuery();
foreach (ListItem i in items) {
Console.WriteLine(i["Title"]);
Console.WriteLine(i["CompanyTitle"]);
}
它是……但是它输出
E01Microsoft.SharePoint.Client.FieldLookupValueE11Microsoft.SharePoint.Client.FieldLookupValueE21
Microsoft.SharePoint.Client而是看"。FieldLookupValue"我想从父列表中查看列的实际内容。
我的代码有什么问题?
明白了
Console.WriteLine(((FieldLookupValue)i["CompanyTitle"]).LookupValue);
把它放在这里是为了帮助别人