c# - MVC Linq query with both group by columns and Max table column -


i'm trying create query gets me unique records of 4 columns plus id column same table.

var newtsonly = newexport.groupby(g => new { g.trainingattended, g.traininglocation, g.trainer, g.dateoftrainingsession }).tolist(); 

the above gets me unique records want can't find way "newexports" "id" field.

my aim create record in different table each unique record require id field other things afterwards.

i've tested in sql query , found work adding max(id) select value still trying work in linq.

select [trainingattended],[trainlocation],[trainer],[dateoftrain], max([id]) id [trainingexport].[dbo].[masterregisterexport] group [trainingattended],[trainlocation],[trainer],[dateoftrain] 

i can't seem find linq equivalent if can give me pointer thanks?

if trying id understood should add new id value:

var newtsonly = newexport.groupby(g => new { g.trainingattended, g.traininglocation, g.trainer, g.dateoftrainingsession, g.id }).tolist(); 

getting max in sql should work this:

var newtsonly = newexport.groupby(g => new { g.trainingattended, g.traininglocation, g.trainer, g.dateoftrainingsession, g.max(x => x.id) }).tolist(); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -