使用 ASP.NET MVC 核心中的工作单元模式,使用从另一个 table 提取的 ID 列表从 table 检索数据

Retrieve data from a table using a list of Ids extracted from another table using the Unit of Work Pattern in ASP.NET MVC Core

目的是从技术人员 table 中检索所有员工的列表。而不是使用该 ID 列表,必须对评论 Table 执行搜索,从而生成这些员工的所有评论的列表。

我使用工作单元和存储库模式进行数据访问。

   tech = unitOfWork.TechnicianRepository.GetAll().Where(b=>b.Branch =="Calgary").AsEnumerable().Select(r => new Review{TechnicianID =r.UserId, }).ToList();

比起在将其发送到视图之前,我将其投射到控制器中

      public IActionResult Index()
      {

        var result = ((IEnumerable)tech).Cast<Review>().ToList();
        return View(result);
      }

以下是 returned 结果之一。

  [{"id":0,"technicianID":"c62a2746-1bfc-484f-a479-084e0be389a4","overAllTechRating":0,"origin":null,"name":null,"feedbackText":null,"date":"0001-01-01T00:00:00"}

从这里可以看出,用户 ID 是从技术人员 table 中提取的,但是对于这些 ID,所有其他字段都显示为空。

以下是自发布问题以来我尝试过的更新:

尝试过的方法:-

    public IActionResult Index()
    {

         var result = unitOfWork.TechnicianRepository.GetAll().Where(b => b.Branch == "Calgary").AsEnumerable().Select(r=> new {r.UserId});

        List<Review> array = new List<Review>();
        while (result != null) {

            array.Add(unitOfWork.ReviewRepository.GetByGuidId(result.First().UserId));
        }
        return View(array);
    }

在尝试这个之后,我能够将我的 UserID 传递给 UnitOfWork GetByGuidId() 函数,但是,它找不到对象,return 一个错误的请求。

这是它的样子:

    public virtual T GetByGuidId(Guid? Id)
    {
        return dbSet.Find(Id);
    }

主要原因可能是 Technician 对象未实例化,因此数据存储从未返回该对象。它返回了 Technician Id,因为它是同一个 table.

中的外键