こんなの用意しておけばいいかなぁ。
using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel.DomainServices.Client; public static class DomainContextExtensions { public static IObservable<IEnumerable<TEntity>> LoadAsObservable<TEntity>(this DomainContext ctx, EntityQuery<TEntity> query) where TEntity : Entity { var subject = new Subject<IEnumerable<TEntity>>(); ctx.Load(query, op => { if (op.HasError) { subject.OnError(op.Error); } else { subject.OnNext(op.Entities); } }, null); return subject.AsObservable(); } }
こんな風に使える。
Observable.FromEvent<MouseButtonEventArgs>(this, "MouseLeftButtonDown") .SelectMany(e => ctx.LoadAsObservable(ctx.GetPeopleQuery())) .Subscribe(people => people.Run(p => Debug.WriteLine(p)));
めもめも。
.