The remmened out does not work, however, the foreach below works fine.
It seems a bit unnecessary to open the Contact twice for updating.
using System;
using System.Linq;
using Xrm;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk;
namespace CSEM_migration
{
public partial class modifycontacts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var xrm = new XrmServiceContext("Xrm");
var GetContacts = xrm.ContactSet
.Where(c => c.StateCode.Value == 0)
.Where(c => c.OwnerId.Equals("26489806-250d-e211-8af5-3c4a92dbd83d"))
.Where(c => c.new_csem_id.Equals(null))
.Take(1000);
//foreach (Contact contact in GetContacts)
//{
// contact.new_csem_id = contact.ContactId.ToString();
// xrm.UpdateObject(contact);
//};
foreach (var contact in GetContacts)
{
ColumnSet cols = new ColumnSet(new String[] { "contactid", "description" });
Contact retrievedContact = (Contact)xrm.Retrieve("contact", new Guid(contact.ContactId.ToString()), cols);
retrievedContact.new_csem_id = contact.ContactId.ToString();
xrm.Update(retrievedContact);
};
}
}
}