Updating CRM entities with LinqtoCRM

If you want to update entities queried with LinqtoCRM, you can't just retrieve entities with all attributes, change something and then update through the web service (a friend of mine worked out why this is so, but I've forgotten). Instead, you need to new up your own entitites and assign the relevant id (which is what CRM uses to determine which entity you're trying to change):

	var res = from c in p.Linq<contact>()
			  where c.fullname.StartsWith("Zwie")
                          // this is the important part
			  select new contact() { contactid = c.contactid };

	foreach (var con in res)
		con.address1_line1 = "foo";
		Console.WriteLine("updated " + con.contactid.Value);

Last edited Mar 7, 2009 at 5:42 PM by friism, version 4


friism Jul 3, 2009 at 9:46 AM 
@decarufe: It's in th SDK http://msdn.microsoft.com/en-us/library/bb928994.aspx

decarufe Jul 2, 2009 at 6:36 PM 
How can I create a new entity?