0

I have three entities ClassC, ClassS and ClassSA. I want to apply group by using LINQ.

using (var db = new SEntities())
{
    var result = from c in db.ClassC
    join s in db.ClassS on c.ID equals s.CID
    join sa in db.ClassSA on s.SAID equals sa.ID
    group sa by
    new { c.Type, s.Date.Year}
    into g
    select new ClassSAY { Year = g.Key.Year, CI = g.Key.CIType, Count = g.Count(sa => sa.ID)};
}

I want to join ClassC, ClassS and ClassSA; group by two different properties of two different classes and store some part of result in another class's properties. I have searched by found group by only one class' properties.

It's giving error:

  1. Cannot convert lambda expression to delegate type 'System.Func<SG.DAL.SA,bool>' because some of the return types in the block are not implicitly convertible to the delegate return type

  2. Cannot implicitly convert type 'long' to 'bool'

Thanks.

Jitendra Gupta
  • 764
  • 1
  • 8
  • 16

1 Answers1

0

Try to use like

Count = g.Count()

instead of

Count = g.Count(sa => sa.ID)
Nitesh Kumar
  • 1,774
  • 4
  • 19
  • 26