Lise Deguilhem

Lise Deguilhem

  • NA
  • 6
  • 568

Need help on linq to sql query

Aug 1 2019 9:27 AM
I am asking for your help regarding a linq query to SQL.
Here is a part of the diagram of my base.
 
 
 
My problem lies in the following relationship:
tbl_607_bottle and tbl_607_gaz_reporting, I can have several reportings for a bottle but reporting can only have one bottle.
 
I do this request but it's not satisfying, i want the last report on each bottle but it return all reports on each bottle. 
 
  1. var GazReportingWizardViewModel = (from gr in db.tbl_607_gaz_reporting  
  2. join a in db.tbl_607_actors on gr.FK_ID_actors equals a.id  
  3. join bo in db.tbl_607_bottle on gr.FK_ID_bottle equals bo.ID  
  4. join loc in db.tbl_607_location on bo.FK_ID_location equals loc.ID  
  5. join cc in db.tbl_607_conformity_certificate on bo.FK_ID_conformity_certificate equals cc.ID  
  6. join j in db.tbl_607_join_bottle_gaz on bo.ID equals j.FK_ID_bottle  
  7. join g in db.tbl_607_gaz on j.FK_ID_gaz equals g.ID  
  8. join od in db.tbl_607_order_details on g.FK_ID_order_details equals od.ID  
  9. where loc.ID == Process   
  10. select new GazReportingWizardViewModel  
  11.        {  
  12.         bottle_conti_number = bo.bottle_conti_number,  
  13.         pressure_value = gr.pressure_value,  
  14.         reporting_date = gr.reporting_date,  
  15.         first_name = gr.tbl_607_actors.first_name,  
  16.         last_name = gr.tbl_607_actors.last_name,  
  17.         expiration_date = cc.expiration_date,  
  18.         content = od.content_comments  
  19.         }).Distinct().OrderBy(t => t.reporting_date).ToList();  
 
Would you have an idea of ​​the solution?
Thank you for your time

Answers (1)