Every article i have found, shows how to add new items using a RIA. Doesnt anyone ever update existing data? It sure doesnt seem like it.
Scenario:
I am using a service from my VM to pull in my Entity. The entity is then edited using the VM from my view. I then want to save my entity back to the database. I dont want to add it. I don't want to delete it. I want to update it. I see the methods for that on the server side, but all I have is submit changes on my datacontext.
I have tried to clone the original entity,then attach the original entity and copy the current entity onto it
public void SaveDoctors(Doctors current, Doctors original, Action<SubmitOperation> callback)
{
var ctx = new RefereeDomainContext();
ctx.Doctors.Attach(original);
original = current;
ctx.SubmitChanges(callback,null);
}
This doesn't work either. I have gone through 10s of blogs today, and anything I have found is always about adding new entities, even when they claim they will show you how to update entities.
I could easily ship the entity to the server side and do it there, but I don't know that that is the correct form to take.
Where is the proper place to be updating Entities? I am using SL5, I am not sure how to tell you what version of RIA Services I am using.
Clarification
I retrieve my entity using a service call from my viewmodel:
Doctors doctors = GetService<IDoctors>.GetDoctor().FirstorDefault(d=>d.id=xxxx);
I push the doctor entity into my VM structure:
DoctorsVM=new DoctorsVM(doctors);
This holds a reference to the doctor that is edited through the properties of the viewmodel. Any Children are filled into ObservableCollections of the children objects.
When I am done with this particular entity and I am ready to save it:
GetService.UpdateCurrentDoctor(DoctorsVM.Doctor)//references the original entity.
This is where I lose it. If I do this: inside my method it doesnt work
var ctx=new DataContext;
ctx.Attach(currentDoctor);//attaches as unmodified
ctx.Add(currentDoctor);//creates a new Entity. Dont want that.
ctx.AttachAsModified is only available on the Server side. ctx.UpdateDoctors is only available on the Server side.
This is where I get lost.
I come from a WPF/Desktop background, so maybe I am just lost in the whole async landscape. And I just need a push in the right direction.