0

I'm Newbi in LinQ, I have problem with group by in linQ.
I wan to query like this:

    select
    MAX(TCheckpointGrouping.Id) AS CheckpointGroupingId,
    MAX(TCheckpointGrouping.MCheckpointId) AS CheckpointId,
    MAX(MCheckpoint.Name) AS CheckpointName,
    MAX(CAST(MCheckpoint.IsMajor AS VARCHAR)) AS IsMajor,
    MAX(TCheckpointGrouping.MIndicatorId) AS IndicatorId,
    MAX(MIndicator.Name) AS IndicatorName,
    MAX(MCriteria.Id) AS CriteriaId,
    MAX(MCriteria.Name) AS CriteriaName,
    MAX(MPrinciple.Id) AS PrincipleId,
    MAX(MPrinciple.Name) AS PrincipleName,
    MAX(TCheckpointGrouping.RelationToCheckPoint) AS RelationToCheckPoint
    from TCheckpointGrouping
    inner join MCheckpoint on MCheckpoint.Id = TCheckpointGrouping.MCheckpointId
    inner join MIndicator on MIndicator.Id = TCheckpointGrouping.MIndicatorId
    inner join MCriteria on MCriteria.Id = MIndicator.MCriteriaId
    inner join MPrinciple on MPrinciple.Id = MCriteria.MPrincipleId
    group by
    TCheckpointGrouping.MCheckpointId,
    TCheckpointGrouping.MIndicatorId

How can i convert query above into LinQ (VB.NET)

thanks bestRegards

e-Beng
  • 11
  • 3
  • possible duplicate of [VB.NET LINQ Group By Multiple Columns](http://stackoverflow.com/questions/12482339/vb-net-linq-group-by-multiple-columns) – Victor Zakharov Apr 24 '13 at 14:17

2 Answers2

2

I'm tempted to convert this SQL query to LINQ for you, but I think that would be a waste of opportunity for you to learn yourself.

There's a great page from Microsoft with lot of VB.NET Linq situations: 101 Linq Samples.

You can even find an example of a Group By using Multiple Columns.

Good learning. :)

J.Hudler
  • 1,238
  • 9
  • 26
0

I am not sure about this, but you can try it. In select part i have not included all the columns.

var result= from TChkgp in TCheckpointGrouping
        join MCpoint in  MCheckpoint on  TChkgp.Id equals MCpoint.Id
    join MIndtor in MIndicator on TChkgp.MIndicatorId equals MIndtor.Id
    join MCrteia in MCriteria on MIndtor.Id equals MIndtor.MCriteriaId
    join MPrncple in MPrinciple on MCrteia.MPrincipleId equals MPrncple.Id
    group TChkgp by new (TChkgp.MCheckpointId,TChkgp.MIndicatorId} into g 
    select new {
    CheckpointGroupingId =TChkgp.Id.Max(),
    CheckpointId =TChkgp.MCheckpointId.Max,
    ....
    ....


    };

you can see one simple example on following link

Group and sum in linq

Community
  • 1
  • 1