
So far we have been focusing on creating and consuming one-way OData feeds (read-only feeds). This time, let us look at how to CREATE, UPDATE and DELETE items. CUD operations are handled by the IDataServiceUpdateProvider and this interface is fully supported by the eXpress Persistent Objects (XPO) Toolkit.
Server Side
Apart from setting the entity access rule to EntitySetRights.All, there is nothing we really need to do on the server side.
Client Side
CREATE
void CreateObject(object entity) {
DataServiceContext service
= new DataServiceContext(new Uri("http://localhost:7676/Service.svc"));
service.AddObject("<EntitySetName>", entity);
service.SaveChanges();
}
UPDATE
void UpdateObject(object entity) {
DataServiceContext service
= new DataServiceContext(new Uri("http://localhost:7676/Service.svc"));
service.AttachTo("<EntitySetName>", entity);
service.UpdateObject(entity);
service.SaveChanges();
}
DELETE
void DeleteObject(object entity) {
DataServiceContext service
= new DataServiceContext(new Uri("http://localhost:7676/Service.svc"));
service.AttachTo("<EntitySetName>", entity);
service.DeleteObject(entity);
service.SaveChanges();
}
Sample Application
To see all CRUD operations in action download the source code for the WinForms Calendar Sample
Resources
Cheers
Azret