Модель просмотра проблемы и запрос LINQ в asp. net mvc - PullRequest
1 голос
/ 07 мая 2020

Я разрабатываю приложение в asp. net MVC, и для отображения нескольких таблиц в одном и том же представлении я создал одну большую ViewModel, которая содержит три модели (сотрудник, пользователь и запрос) Теперь моя проблема - мой запрос, который не работает, и я не могу найти проблему
Спасибо за вашу помощь Извините за мой английский sh не подходит

My bigviewmodel 

    namespace freegest.Models
{
    public class ControleViewModel
    {

        public List<employe> employes { get; set; }
        public List<demande > demandes  { get; set; }
        public List<utilisateur> utilisateurs  { get; set; }



    }
}

Мой запрос

 public ActionResult listdemande()
    {


        int id = Convert.ToInt32(Session["id_utilisateur"]);

        ControleViewModel CV = new ControleViewModel();

        CV = (from a in CV.utilisateurs
              join b in CV.demandes
              on a.id_utilisateur equals b.idutilisateur_demande
              join c in CV.employes
              on a.idemploye_utilisateur equals c.id_employe
              orderby c.nom_employe ascending
              where a.id_utilisateur == id
              select new ControleViewModel
              {
                  c.nom_employe ,

              });

        return View(CV);

    }

1 Ответ

0 голосов
/ 08 мая 2020

Попробуйте следующий подход для объединения нескольких таблиц с помощью LINQ:

public ActionResult Index()  
{  
    using (DBEntities db=new DBEntities())  
    {  
        List<Employee> employees = db.Employees.ToList();  
        List<Department> departments = db.Departments.ToList();  
        List<Incentive> incentives = db.Incentives.ToList();  

        var employeeRecord = from e in employees  
                             join d in departments on e.Department_Id equals d.DepartmentId into table1  
                             from d in table1.ToList()  
                             join i in incentives on e.Incentive_Id equals i.IncentiveId into table2  
                             from i in table2.ToList()  
                             select new ViewModel  
                             {  
                                 employee=e,  
                                 department=d,  
                                 incentive=i  
                             };  
        return View(employeeRecord);  
    }  
}  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...