문제

I'm developing an automation of manual system for a fuel pump. Up till now I've accomplished my tasks but now I'm stuck on something related to retrieve data from multiple related tables into one data grid view. I've already 'Google' my problem but failed to find the right way to move on. Here is my scenario Explanation:

  • I've table named 'Department' which have 'Vehicles' table; (1-*) relation.
  • then 'Vehicles' table have 'Months' table to keep monthly billing details; (1-*) relation.
  • and 'Months' table have tow tables 'Fuel_Bill' and 'Lubi_Bill' to keep the top level information of bills.(Both have 1-1 relation with 'Months' table).

I've build this using entity-framework designer first model on SQL LocalDB.

So, now I'm stuck on showing: -Department's monthly abstract view which have the details related to 'Vehicles' and the 'Fuel _bill" details of selected 'Month' in one data grid view.

It's a long question but to be clear I give these details, Please help me out, my whole project will fail if I can't accomplish this.

Any help will be appreciated. Thanks in advance.

I'm adding links to pictures of my data base structure.

Entity Framework model:

Model

And what I'm trying to achieve:

View

도움이 되었습니까?

해결책

I would start from context.Months to collect the required data for your grid:

var viewModels = context.Months
    .Where(m => m.Month_Name == selectedMonthName &&
        m.Vehical.Dept_Id == selectedDepartmentId)
    .Select(m => new
    {
        Vehc_Number = m.Vehical.Vehc_Number,
        FB_Id = m.Fule_Bill.FB_Id,
        LB_GTAmount = m.Fule_Bill.LB_GTAmount,
        LB_GTQuantity = m.Fule_Bill.LB_GTQuantity
    })
    .ToList();

viewModels will be a list of anonymous objects with those four properties that you want to show in the grid. It should be possible to bind this list to the grid view.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top