What is the difference between service.Create and orgContext.AddObject?
dynamics-crm, dynamics-crm-2011
Solution
Part A uses the raw create method of the organization service proxy. This operation directly creates the record.
Part B makes use of the OrganizationServiceContext, which implements the Unit of Work pattern. Your operations are not transmitted to the server until you call `SaveChanges()`
Which is better? It depends on your requirements. If you only want to create a record on the go -> use the service. If you do multiple things which form a logical unit take version B.
Problem
I find that there are two ways at least to create a record in an entity like the following. Common Part ``` var record = new someEntity() { attribute1="test1", attribute2="test2" }; var service = new OrganizationService("CrmConnectionString"); ``` Part A ``` service.Create(record); ``` Part B ``` var orgContext = new OrganizationServiceContext(service); orgContext.AddObject(record); orgContext.SaveChanges(); ``` What is the difference?And which is better?