How to GroupBy different tables on same fieldname

Hi,

I need to group by on different tables where the field is always the same: Id.

This is the sqlexpression


.GroupBy<LRDDevice, LRAContenitore>((d, c) => new { d.Id, c.Id } )

but VS complains:

Error CS0833 An anonymous type cannot have multiple properties with the same name LabReboot.ServiceLogic

I switched to GroupBy<LRDDevice>(d => d.Id).thenBy<LRAContenitore>(c => c.Id ) but without results.

Any suggestions?

Thanks.

Can you please provide the complete OrmLite Query and can you make sure the Table Joins are declared first after db.From<T> (if not already).

Note: The ThenBy only applies to ORDER BY not GROUP By

This is the query

var q = Db.From<LRARichiesta>();
q.Join<LRARichiesta, LRAContenitore>((aRichiesta, aContenitore) => aRichiesta.Id == aContenitore.RichiestaId);
q.Join<LRAContenitore, LRAAnalisi>((aContenitore, aAnalisi) => aContenitore.Id == aAnalisi.ContenitoreId );
q.Join<LRAAnalisi, LRAListaDiLavoro>((aAnalisi, aListaLav) => aAnalisi.Id == aListaLav.AnalisiId);
q.Join<LRAListaDiLavoro, LRDDevice>((aListaLav, dDevice) => aListaLav.ListaDiLavoroId == dDevice.ListaDiLavoroId);
q.Where<LRARichiesta>(x => x.Archiviato == 0);
q.And<LRAAnalisi>(x => x.LaboratorioEsecutoreCandidatoId == laboratorioId);
q.GroupBy<LRDDevice, LRAContenitore>((device, contenitore ) => new { device.Id, contenitore.Id });
q.Select<LRDDevice>(x => new { x.Id, Total = Sql.Count("*") });

The IDE is Visual Studio 2015 with .NET Framework 4.5.2

This is a C# compilation error because you can’t have an anonymous type with the same property name. You can use an alias to give the anon type field a different C# name, e.g:

q.GroupBy<LRDDevice,LRAContenitore>((dev,cont) => new { dev.Id, ContId = cont.Id });

Good, it work’s.

It was so simple.

Thanks.