views:

57

answers:

2

I need to build a query to the entities to get records including:

  • AssetWeapon,
  • PersonOut
  • number of records with IsIn = True,
  • number of records with IsIn = False,
  • name of the month of StartTime,

Records should be grouped by AssetWeapon

thank you guys!

alt text

A: 

Maybe this article could help you:

http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx

look projection operators..

Rbacarin
thank's! it helped
Ike
A: 

here what I've got finally:

var query = from ta in db.Transactions_Assets.Include("Transaction")
                        let items = new
                        {
                            Weapon = ta.AssetWeapon,
                            Month = ta.Transaction.StartTime.Value.Month,
                            IsIn = ta.IsIn 
                        }
                        group items by items.Weapon into g
                        select new { 
                            Weapon = g.Key,
                            MonthlyFlow = from m in g 
                                    group m by m.Month into mg
                                    select new { Month = mg.Key, 
                                                 Ins = mg.Count( x => x.IsIn == true),
                                                 outs = mg.Count(x => x.IsIn == false)
                                    }
                        };
Ike