简体   繁体   English

如何获取完整的数据,包括2个表和2个关联表?

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

I need this method for the GET Request. 我需要此方法的GET请求。 I want the fleetdatas including the rest_Days and delivery_Days. 我想要的车队数据包括rest_Days和delivery_Days。

This is for the Web-Server. 这是针对Web服务器的。 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 我想获取所有车队数据,包括delivery_Days和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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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