I have a data structure for an automation device. It has multiple outputs, those are organized into a layout.
public class AutomationLayout
{
public Pin D0 { get; set; }
public Pin D1 { get; set; }
public Pin D2 { get; set; }
public Pin D3 { get; set; }
public Pin D4 { get; set; }
public Pin D5 { get; set; }
public Pin D6 { get; set; }
public Pin D7 { get; set; }
public Pin D8 { get; set; }
public Pin D9 { get; set; }
}
Each output has multiple dependencies.
public class Pin
{
public string Name { get; set; }
public string DigitalSensor { get; set; }
public Schedule Schedule { get; set; }
public ClimateControl ClimateControl { get; set; }
public TempRange TempRange { get; set; }
public VoltRange VoltRange { get; set; }
}
And those classes are also full of properties.
I have used Database first approach with EF Core.
I am mapping the created models to DTOs and use these in my controller.
public static class DeviceDtoMapper
{
public static DeviceGetDto MapDeviceToGetDto(Device device)
{
return new DeviceGetDto()
{
Id = device.Id,
Name = device.Name,
CreatedAt = device.CreatedAt
};
}
public static Device MapPostDtoToDevice(DevicePostDto deviceDto)
{
return new Device()
{
Name = deviceDto.Name,
CreatedAt = DateTimeOffset.Now.ToString()
};
}
public static Device MapPutDtoToDevice(DevicePutDto deviceDto)
{
return new Device()
{
Name = deviceDto.Name
};
}
}
I am trying to write a controller to GET the complete automation layout.
The problems is it would require more than a 1000 Include() and ThenInclude() lines, which does not seem to be very efficient.
If possible I would avoid including all the navigation properties.
How can I deal with this data structure?
Thanks in advance.