How do I join and aggregate two observable collections?

Nov 24, 2011 at 8:33 PM

I want to be able to do a simple left outer join (or just join) and then group (sum) some columns.

I couldn't figure out how is that possible with Obtics.

Thanks.

Coordinator
Nov 26, 2011 at 10:59 AM

How would you do it using object linq?

if <exp> is your linq expression giving your result you would just do:

ExpressionObserver.Execute(<exp>)

In case your <exp> is supposed to return a collection of values do:

ExpressionObserver.Execute(<exp>).Cascade()

Regs,

Thomas

Dec 2, 2011 at 11:07 AM

I can't get this query to work.

            _query = ExpressionObserver.Execute(() =>

                                                (from q in _quotes
                                                where q.Exchange == "#FX" && q.Provider == ProviderEnum.Bloomberg
                                                //join qt in _currencies on q.Isin equals qt.Isin into joinObj1 from joinObj2 in joinObj1.DefaultIfEmpty(new QuoteTickViewModel())
                                                //where joinObj2.Provider == ProviderEnum.Tradebase
                                                 select q).Join(_currencies.Where(es => es.Provider == ProviderEnum.Tradebase)
                                                , i => i.Isin, x => x.Isin, (h, p) => new { blbisin = h.Isin, blbprice = h.Last, blbprovider = h.Provider, tbmxisin = p.Isin, tbmxprice = p.Last, tbmxprovider = p.Provider })
 
                                                ).Cascade();

First I've tried with normal LINQ expression to join and then I've wrote it as chained query. I can see the values in the grid but they are not updating.

Thanks.

Dec 5, 2011 at 12:36 PM

I think the problem is Anonymous types.. Is it possible?

Dec 6, 2011 at 9:13 AM
Edited Dec 6, 2011 at 11:13 AM

Sorry it was my Linq Expression. It should have been like this.

           var query = ExpressionObserver.Execute(() =>
                                                  from q in _quotes.Where(p => p.Provider == ProviderEnum.Bloomberg)
                                                  from qp in
                                                      _currencies.Where(
                                                          j => j.Isin == q.Isin && j.Exchange == q.Exchange && j.Provider == ProviderEnum.Tradebase)
                                                      .DefaultIfEmpty(new QuoteTickViewModel())
                                                  select
                                                      new
                                                          {
                                                              IsinB = q.Isin,
                                                              IsinT = qp.Isin,
                                                              ExchangeB = q.Exchange,
                                                              ExchangeT = qp.Exchange,
                                                              PriceB = q.Last,
                                                              PriceT = qp.Last,
                                                              ProviderB = q.Provider,
                                                              ProviderT = qp.Provider
                                                          }
               ).Cascade();

If I try it with a normal LINQ/SQL-Like syntax (join into) then it does not function.
This syntax is obviously not compatible with Obtics;

           var query = ExpressionObserver.Execute(() =>
                                                  from q in _quotes.Where(f => f.Provider == ProviderEnum.Bloomberg)
                                                  join qp2 in _currencies.Where(x => x.Provider == ProviderEnum.Tradebase) on new {q.Isin, q.Exchange} equals new {qp2.Isin, qp2.Exchange } into temp
                                                  from qp in temp.DefaultIfEmpty(new QuoteTickViewModel())
                                                  select new
                                                             {
                                                                 IsinB = q.Isin,
                                                                 IsinT = qp.Isin,
                                                                 ExchangeB = q.Exchange,
                                                                 ExchangeT = qp.Exchange,
                                                                 PriceB = q.Last,
                                                                 PriceT = qp.Last,
                                                                 ProviderB = q.Provider,
                                                                 ProviderT = qp.Provider
                                                             }).Cascade();

 

Coordinator
Dec 6, 2011 at 5:57 PM

Good that you found a solution. 'join into' syntax should work though but there may always be a bug.

Could you create a unit test that isolates your problem?

Regs,

Thomas.

Dec 14, 2011 at 2:44 PM

I'm sorry for the late answer.

My Project is not entirely unit-testable. But I can say that it's just an observablecollection for items with inotifypropertchanged interface.

There are some nullable properties in items, I wanted to check them but right now I don't have time for that, I needed quick solutions and workarounds :)