Update 2 : @Enigmativity has a brilliant answer. I've implemented this into a IObservableRepository<T>. Details in my answer below.
Question: So I've changed most of the question (See edit history) I would just like it if someone commented/validated/puked on my design. =)
So typically my Repos look like this:
public interface IRepository<T> where T : class
{
T GetById(int id);
IQueryable<T> GetAll();
void InsertOnSubmit(T entity);
void DeleteOnSubmit(T entity);
int SubmitChanges();
}
But when it comes to Silverlight and WCF Data Services, it gets seriously annoying query related data with all the asynchrony. I have to load the parent entity async first and then query its child entities async.
So I came up with an IAsyncRepository, I'd like to know if the design is ok, whether it could be improved, (and whether it makes any sense using Rx here?)
To Solve the child entities problem I plan to load all required child entities before calling the callback.
My Repo looks like:
public interface IAsyncRepository<T> where T : class
{
void GetById(int id, Action<T> callback);
void GetAllFromQuery(Func<MyEntities, IQueryable<Product>> funcquery,
Action<IList<Calculator>> callback)
}
You could use the repo like this:
productRepo.GetAllFromQuery(
x => x.Products.Where(p => p.ID > 5),
y => Assert.IsTrue(y.Count > 0)); //y is a IList<Product>
What do you guys think?
Regards, Gideon