前回書いたプログラムですが、LINQ星人として有名なid:neueccさんからZipメソッド内で副作用のあることをするのはいくない!って言われたので書き直してみました。
private EduDomainContext ctx = new EduDomainContext(); public void Load() { this.IsBusy = true; // 読み込み開始! var cust = this.ctx.LoadAsObservable(this.ctx.GetCustomersQuery(1000)); var supp = this.ctx.LoadAsObservable(this.ctx.GetSuppliersQuery(2000)); cust.Zip(supp, (customer, supplier) => new { customer, supplier }) .SelectMany(data => this.ctx.LoadAsObservable(this.ctx.GetOrdersQuery(2000)) .Select(order => new { data.customer, data.supplier, order })) .Subscribe( data => { this.Customers.Source = data.customer; this.Suppliers.Source = data.supplier; this.Orders.Source = data.order; }, ex => { this.Message = ex.Message; this.IsBusy = false; throw new Exception("だめぽ", ex); }, () => { this.IsBusy = false; }); }
インフルで解熱剤が効いてる間に寝るのでコードを張るだけで失礼します。