Marius Vasile

Marius Vasile

  • 594
  • 1.9k
  • 145.6k

How can I join two unrelated table in a SelectList?

Dec 11 2020 1:39 AM
I have two unrelated tables and I want to join PTWTypeName from first table and PTWTypeNameOrg from the second one into a SelectList.
 
  1. public class PTWType  
  2.     {  
  3.         [Key]  
  4.         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  5.         public string PTWId { getset; }  
  6.         public string PTWTypeName { getset; }  
  7.     }  
  8.     public class PTWTypeOrg  
  9.     {  
  10.         [Key]  
  11.         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  12.         public string PTWIdOrg { getset; }  
  13.         public string PTWTypeNameOrg { getset; }  
  14.         public string OrgID { getset; }  
  15.     }  
 What I tried is
 
  1. var ptwType = await _context.PTWTypesOrg  
  2.                                  .Join(_context.PTWTypes, t1 => t1.PTWTypeNameOrg, t2 => t2.PTWTypeName, (t1, t2) => new  
  3.                                  {  
  4.                                      PTW1 = t1.PTWTypeNameOrg,  
  5.                                      PTW2 = t2.PTWTypeName,  
  6.                                  }).ToListAsync();  
  7.   
  8.             PTWTypeSL = new SelectList(ptwType);  
but no result in the SelectList 

Answers (1)