Update 2 : @Enigmativity has a brilliant answer. I\'ve implemented this into a IObservableRepository
. Details in my answer below.
Too long to update the question, so I posted as an answer.
So I implemented it like this:
public interface IObservableRepository
{
IObservable GetById(int id);
IObservable> GetAll(Func> funcquery);
IObservable SubmitInserts(IList inserts);
IObservable SubmitDeletes(IList deletes);
IObservable SubmitUpdates(IList updates);
//helpers
IObservable SubmitInsert(T entity);
IObservable SubmitDelete(T entity);
IObservable SubmitUpdate(T entity);
}
Some notes :
TContext
is needed for GetAll()
, the implementation will have the Entity Framework DataServiceContext
which will allow you to do the following:
var foos = repo.GetAll(ts => ts.Where(t => t.Bar == "Hello"));
//ts is a DataContext passed here by GetAll();
//helpers
just call the other methods that take arrays.DataServiceResponse
. What I do is loop through them and return the Http Status Codes. So the ints returned for the CRUD methods are Http Status Codes.When loading child entities I just eager loaded them by doing this:
context.Products.Expand("Child").Expand("Child2");
I can basically use it like this:
productRepo.GetById(3).Subscribe(x => /* Do something with product x*/ );
productRepo.SubmitUpdate(product)
.Subscribe(r => /*return code should be 204 (http) 201 for insert */);
//same for insert and delete
Do tell me if I should put up the actual implementation here.
Any comments on this would be well taken =)
Thanks