简体   繁体   中英

How do I get the full data, including 2 tables and 2 associative tables?

I need this method for the GET Request. I want the fleetdatas including the rest_Days and delivery_Days.

This is for the Web-Server. Inserting in the database is already working.

//Fleetdata Entity
public class Fleetdata : EntityObject
{
    public string Ad_Ma { get; set; }
    public string Id_Ma { get; set; }
    public string CustomerNr { get; set; }
    public string First_Delivery { get; set; }
    public bool Want_Key { get; set; }
    public bool Rb_Change { get; set; }
    public bool Pallet_Delivery { get; set; }
    public string Name { get; set; }
    public string Company_Name { get; set; }
    public string Street_HouseNr { get; set; }
    public string Postalcode_Place { get; set; }
    public string Phone { get; set; }
    public string Mobilephone { get; set; }
    public string Fax { get; set; }
    public string Email { get; set; }
    public string Important_Infos { get; set; }
    public bool Delivery_After { get; set; }
    public string Delivery_Point { get; set; }
    public string Delivery_Time_Window { get; set; }
    public List<FleetdataRestday> Rest_Days { get; set; } = new 
    List<FleetdataRestday>();
    public List<FleetdataDeliveryday> Deliverydays { get; set; } = new List<FleetdataDeliveryday>();
}

//Delivery_Day Entity
public class Delivery_Day : EntityObject
{
    public string Weekday { get; set; }
    public List<FleetdataDeliveryday> Fleetdatas { get; set; } = new 
    List<FleetdataDeliveryday>();
}

//Associative table
public class FleetdataDeliveryday
{
    public int FleetdataId { get; set; }
    public int DeliveryDayId { get; set; }
    public Fleetdata Fleetdata { get; set; }
    public Delivery_Day Delivery_Day { get; set; }
}    

//My GetAll Method
public List<Fleetdata> GetAll()
{
    return _dbContext.Fleetdatas
        .Include(x => x.Rest_Days)
        .Include(x => x.Rest_Days.Select(r => r.Rest_Day))
        .Include(y => y.Deliverydays)
        .Include(y => y.Deliverydays.Select(d => d.Delivery_Day))
        .ToList();
}

I want to get all fleetdatas including delivery_Days and rest_Days

return _dbContext.Fleetdatas
     .Include(x => x.Rest_Days)
     .ThenInclude((FleetdataRestday fr) => fr.Rest_Day)
     .Include(y => y.Deliverydays)
     .ThenInclude((FleetdataDeliveryday fd)  => fd.Delivery_Day)
     .ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM