Do I need to call the domain service context. Save changes after adding a new object?

I am building an application based on Ria Services.

Among the default methods that were created by the Visual Studio wizard, I see those that need to insert and save new data.

For instance:

public void InsertCustomer(Customer customer) { if ((customer.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(customer, EntityState.Added); } else { this.ObjectContext.Customers.AddObject(customer); } } 

However, I do not see this. In order to insert an object into the data warehouse, you need to call the ObjectContext.SaveChanges () object, which I read .... do I need to change these functions to save the information?

Thanks in advance, Hooray, Gianluca.

+4
source share
2 answers

When you call SubmitChanges on the client, it calls DomainService.Submit on the server. The default implementation then invokes several protected virtual methods sequentially, including AuthorizeChangeSet, ValidateChangeSet, ExecuteChangeSet, and PersistChangeSet. Your CUD operation will be called from ExecuteChangeSet and ObjectContext.SaveChanges () will be called from PersistChangeSet.

You do not need to change the default methods to save information, since the default will take care. However, the design gives you the ability to redefine pieces of the send pipeline if you need more complex scripts.

+4
source

What you should do is something like this:

 //Create an instance of your Domain context in your class. YourDomainContext context = new YourDomainContext(); if (context.HasChanges) { context.SubmitChanges(so => { string errorMsg = (so.HasError) → "failed" : "succeeded"; MessageBox.Show("Update " + errorMsg); }, null); } else { MessageBox.Show("You have not made any changes!"); } 

Please take a look at this in this article: Using WCF RIA Services Or look at this video: Silverlight Firestarter 2010 Session 3 - Creating Feature Rich Business Applications Today with RIA Services

0
source

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


All Articles