适用于Silverlight 4 + WCF数据服务的IAsyncRepository或IObservableRepository(IAsyncRepository or IObservableRepository for silverlight 4 + WCF Data Services)
更新2 :@Enigmativity有一个很好的答案。 我已将其实现为
IObservableRepository<T>
。 我的答案详情如下。
问:所以我已经改变了大部分问题(参见编辑历史)如果有人对我的设计进行了评论/验证/推测,我会喜欢它。 =)
所以通常我的Repos看起来像这样:
public interface IRepository<T> where T : class { T GetById(int id); IQueryable<T> GetAll(); void InsertOnSubmit(T entity); void DeleteOnSubmit(T entity); int SubmitChanges(); }
但是当谈到Silverlight和WCF数据服务时,它会使所有异步的查询相关数据变得非常烦人。 我必须首先加载父实体异步,然后查询其子实体异步。
所以我提出了一个
IAsyncRepository
,我想知道设计是否正常,是否可以改进,(以及在这里使用Rx是否有意义?)要解决子实体问题,我计划在调用回调之前加载所有必需的子实体。
我的回购看起来像:
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) }
您可以像这样使用repo:
productRepo.GetAllFromQuery( x => x.Products.Where(p => p.ID > 5), y => Assert.IsTrue(y.Count > 0)); //y is a IList<Product>
你们有什么感想?
问候,吉迪恩
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
原文:https://stackoverflow.com/questions/5349140