Mouhssine tahri

Mouhssine tahri

  • NA
  • 201
  • 11.3k

(Group)Join if you can't use the ICollection

Oct 27 2020 4:49 AM
Hi,
 
I have 2 table :(User and Service) with relation many to many
 
the EF create third table ServiceUserDiff
  1. public partial class User  
  2. {  
  3. public int UserID { getset; }  
  4. public string FirstName { getset; }  
  5. public string LastName { getset; }  
  6. public virtual ICollection<ServiceUserDiff> UserDiffToService { getset; }  
  7. }  
  8. public partial class Service  
  9. {  
  10. public int CodeService { getset; }  
  11. public string DesignationService { getset; }  
  12. public virtual ICollection<ServiceUserDiff> ServiceToUserDiff { getset; }  
  13. }  
  14. public partial class ServiceUserDiff  
  15. {  
  16. public Nullable<int> IdUserDiffService { getset; }  
  17. public Nullable<int> IdServiceUserDiff { getset; }  
  18. public Nullable<int> AttributaireON { getset; }  
  19. public int IdDiff { getset; }  
  20. public virtual Service ServiceDiff { getset; }  
  21. public virtual User UserDiff { getset; }  
  22. }  
i create function to get information from 3 table
  1. public List<ServiceUserDiff> GetAllServiceUserDiff()  
  2. {  
  3. var listServiceUserDiff = bd.Service.GroupJoin(bd.ServiceUserDiff,  
  4. service => service.CodeService,  
  5. serviceUserDiff => serviceUserDiff.IdServiceUserDiff,  
  6. (service, serviceUserDiff) => new  
  7. {  
  8. serviceCode = service.CodeService,  
  9. serviceDsg = service.DesignationService,  
  10. user = serviceUserDiff.Join(bd.User,  
  11. serviceUserDiffs => serviceUserDiffs.IdUserDiffService,  
  12. user => user.UserID,  
  13. (user, serviceUserDiffs) => new  
  14. {  
  15. IdUser = serviceUserDiffs.UserID,  
  16. NameLast = serviceUserDiffs.LastName,  
  17. NameFirst = serviceUserDiffs.FirstName  
  18. }).ToList(),  
  19. });  
  20. return listServiceUserDiff;  
  21. }  
this function generates me the next error message:
 
Cannot implicitly convert type system linq IQueryable to system collections generic List
 
thanks for your help

Answers (6)