我这里有这组数据。事件有一个EventGroups
类型的属性List<Groups>
List<Events> e;
List<Groups> g;
// Get the data from the database using dapper
using( var con = DataAccessMaster.GetOpenConnection( ) ) {
using( var multi = con.QueryMultiple( sprocname, new { StartDate = fromDate, EndDate = toDate }, commandType:CommandType.StoredProcedure ) ) {
e = multi.Read<Events>( ).ToList( );
g = multi.Read<Groups>().ToList();
}
}
// Only put the groups that belong to one another within the related event so that when we goto bind it will be painless
foreach ( var ev in e ) {
ev.EventGroups = new List<Groups>();
foreach ( Groups group in g.Where( Groups => ( ev.EventID == Groups.EventID ) ) ) {
ev.EventGroups.Add( group );
}
}
return e;
我觉得最后一个块可以比现在更干净地重写。我该怎么做才能使这个更清洁?