umair mohsin

umair mohsin

  • 1k
  • 387
  • 65.7k

how to arrange data properly using linq

Sep 30 2024 6:04 PM

let i have a candidate table in which few records are there and some other tables related to a candidate(one to many relation) i fetch a candidate from a table and based on the id i fetch records from other tables and each table has four to five or more rows in it. 

so there is a bulk of data related to single candidate.

i want to know if  i use linq to fetch records so what would be the query for fetching. i am designing the app in mvc pattern.

so i declare Ienumrable fields in my model to display records(lists) related to a specific candidate.

 

A test case:

db.candidates.where(i=>i.canid=someid).

can.academics=db.academics.where(a=>a.id==can.id).toList(); 

the academics would be displayed to view accordingly.further fields are also there, additionally candidate has its own data too.

i want to know that for a test case, is there any way i can join these two tables (or more) 

 

   can.tbl1= tbl1.GetListById(can.CanId).ToList();
           can.tbl2 = tbl2.GetListById(can.CanId).ToList();
            can.tbl3 = tbl3.GetListById(can.CanId).ToList();
            can.tbl4= tbl4.GetListById(can.CanId).ToList();

Note:GetListById()could be any method.

my question is that is this a practical way to populate data or should i follow any other way 
            

 


Answers (2)