umair mohsin

umair mohsin

  • 1.3k
  • 382
  • 63.2k

what is more suitable looping or db calls

Oct 1 2024 8:59 PM

this is the extension of my previous question if for any reason i have to join multiple tables( 7 to 8) and if use linq in an mvc app like this:

 

 var data = (from a in context.GetModel()
                            join ad in aContext.GetModel() on a.CanId equals ad.CanId
                            join b in bContext.GetModel() on a.CanId equals b.CanId
                            join c in clContext.GetModel() on a.CanId equals b.CanId
                            join d in dContext.GetModel() on a.CanId equals d.CanId

                            where a.Id == id
                            select new
                            {

                                ac = ad,
                                ce = b,
                                skill = c,
                                exp = d

                            }).ToList() ;

 so it proves that its a huge query which has a bulky out put as each join table has multple rows related to a candidate

 

i have to loop through data variable to fetch data from anonymous variables(ce,skill exp,....). for this i have to run 4 loops.

is there any other way to get these values without looping 

OR

should i use db calls four times. what is more feasible or i must say best  industry practices?


Answers (5)