basquang™ on clouds

May 17, 2013

Update Single/Multiple Lookup field in SharePoint 2010 using WCF Data Services, REST API, C#

Filed under: SharePoint,WCF — basquang @ 11:03 AM

If you want to use SharePoint 2010 WCF Data Services to update SharePoint lookup field in a list; you need remember following things:

To update single Lookup field: Use Id to reference to the looked up list object to the target list object similar as the code below:

item.CompetencyId = competency.Id; //Add looked up list item object by ID
dc.UpdateObject(item);             //Update the target object
dc.SaveChanges();		      //Save changes from data context

 

To update a lookup field that allow multiple values: Use the AddLink(object source, string sourceProperty, object target) from datacontext with the System.Data.Services.Client.SaveChangesOptions.Batch mode similar as the code below:

//Add multiple link to the target list object
foreach(var competency in competencies)
	{
		dc.AddLink(item, "Competency", competency);
	}
dc.UpdateObject(item);               
//SaveChanges in batch mode
dc.SaveChanges(System.Data.Services.Client.SaveChangesOptions.Batch);

 

Hope this help!

Advertisements

2 Comments »

  1. Thầy Quang viết 1 bài về ứng dụng kết nối và truy cập csdl SQLite cho bọn em tham khảo với

    Comment by Duc Tuan — May 30, 2013 @ 10:40 AM | Reply

  2. Úng dụng database cho nền tảng WP8 và viết theo mô hình chuẩn MVVM

    Comment by Duc Tuan — May 30, 2013 @ 10:41 AM | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: