Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 470.7k

How to join three tables using join in entity framework?

Apr 21 2021 9:56 PM
How to join three tables in entity framework, i have two different models. My logic is as follows i am bit stuck.
  1.     public class ExtractionViewModel  
  2.     {  
  3.         public DateTime Year { getset; }  
  4.   
  5.         public int Week { getset; }  
  6.   
  7.         public DateTime Day { getset; }  
  8.   
  9.         public string Model { getset; }  
  10.     }      
  11.   
  12.  public partial class WeekDetail: IEntity  
  13.     {  
  14.         public System.Guid WeekId { getset; }  
  15.         public int WeekNum { getset; }  
  16.         public string Year { getset; }  
  17.         public Nullable<int> ScheduleTotal { getset; }  
  18.         public System.DateTime CreatedDate { getset; }  
  19.         public string CreatedBy { getset; }  
  20.         public System.DateTime ModifiedDate { getset; }  
  21.         public string ModifiedBy { getset; }  
  22.         public bool InActive { getset; }  
  23.   
  24. public IList<ExtractionViewModel> GetExtractionViewModels()  
  25.         {  
  26.             ProductionManagementEntities db = new ProductionManagementEntities();  
  27.   
  28.             var scheduleList = (from s in db.Schedules  
  29.                               join w in db.WeekDetails on   
  30.                               select new ExtractionViewModel  
  31.                               {  
  32.                                 Year = s.ModifiedDate,  
  33.                                 Week = s.  
  34.                               }).ToList();  
  35.             return scheduleList;  
  36.         }  
  37.         public ActionResult ExportToExcel()  
  38.         {  
  39.   
  40.             var v = new GridView();  
  41.            // v.DataSource = this.GetExtractionViewModels();  
  42.             v.DataBind();  
  43.             Response.ClearContent();  
  44.             Response.Buffer = true;  
  45.             Response.AddHeader("content-disposition""attachment; filename=ExtractionRecords.xls");  
  46.             Response.ContentType = "application/ms-excel";  
  47.             Response.Charset = "";  
  48.             StringWriter objStringWriter = new StringWriter();  
  49.             HtmlTextWriter htmlTextWriter = new HtmlTextWriter(objStringWriter);  
  50.             v.RenderControl(htmlTextWriter);  
  51.             Response.Output.Write(objStringWriter.ToString());  
  52.             Response.Flush();  
  53.             Response.End();  
  54.             return View("List");  
  55.         }  

Answers (2)