locked
How to write the given query in pattern repository RRS feed

  • Question

  • User1661386615 posted

    this is code of with out pattern repository

     var expenseOrderDetails = db.ExpenseOrderDetails.Include(e => e.ExpenseOrder).Include(e => e.ExpenseType).Include(e => e.Vendor);
                return View(await expenseOrderDetails.ToListAsync());

    this is the code of with Unit of work but it give error i dnt know why kindly suggest me the correct way to write a query for it in Pattern Respository

     var expenseOrderDetails=_unitOfWork.ExpenseOrderDetails.Include(e => e.ExpenseOrder).Include(e => e.ExpenseType).Include(e => e.Vendor);
     return View(await _unitOfWork.ExpenseOrderDetails.GetAllAsync());

    Sunday, November 8, 2020 2:27 AM

All replies

  • User-939850651 posted

    Hi Syed Ammar Bukhari,

    Based on your description, could you describe the general content of db and _unitOfWork? This will help us to reproduce the problem you encountered.

    And the repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application, So I think the unit of work is not equal to DbContext.

    You could also refer to the following two links for more detailed information:

    Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application

    Repository Pattern C#

    Best regards,

    Xudong Peng

    Monday, November 9, 2020 8:52 AM