I have the following Transact SQL query using a union. I need some pointers as to how this would look in LINQ i.e some examples wouldbe nice or if anyone can recommend a goo
There are the 101 Linq Samples - with two union samples Union1 and Union2
This Linq statement should get you the same results as your SQL: (it has for me on a test record-set)
var results = (from a in (from d in DiscountPromotions
group d by d.BarCode into g
select new {
BarCode = g.Key,
AmountTaken = g.Sum(p => p.AmountTaken)
}).Union(from i in ItemSaleTransactions
group i by i.BarCode into o
select new {
BarCode = o.Key,
AmountTaken = o.Sum(i => i.AmountTaken)
}) group a by a.BarCode into b
select new {
BarCode = b.Key,
AmountTaken = b.Sum(c => c.AmountTaken)
});