What is the difference between service.Create and orgContext.AddObject?

I found that there are two ways to at least create a record in an entity similar to the following.

a 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?

+4
source share
1 answer

Part A uses the raw create method of the organization's proxy server. This operation directly creates a record.

Part B uses the OrganizationServiceContext, which implements the Work Block . Your operations are not transferred to the server until you call SaveChanges()

What's better? It depends on your requirements. If you want to create a record on the go → use this service. If you are doing several things that make up a logical unit, use version B.

+8
source

Source: https://habr.com/ru/post/1411693/


All Articles