在 ServiceStack 中使用 ResponseDTO 自动查询

AutoQuery with ResponseDTO in ServiceStack

我使用以下代码在 API 中创建了一个 AutoQuery 函数。

[Route("/cars/search")]
public class SearchCars : QueryDb<Car, CarDto>,  IJoin<Car, Equipment, Colour, FuelType, Manufacturer>
{
    public List<int> EquipmentIds { get; set; }
    public List<int> ManufacturerIds { get; set; }
    public List<int> ColourIds { get; set; }
}

CarDto 看起来像这样

public class CarDto
{
    public int Id { get; set; }

    public List<Equipment> Equipment { get; set; }

    public Manufacturer Manufacturer { get; set; }
    public int ManufactorId { get; set; }

    public FuelType FuelType { get; set; }
    public int FuelTypeId { get; set; }

    public byte[] ProfileImage { get; set; }
}

我想知道 IJoin 是否寻找任何特定值,因为当我尝试使用它时我得到 "Could not infer relationship between Car and Equipment"

汽车长这样。

    [AutoIncrement]
    public int Id { get; set; }

    public int FuelTypeId { get; set; }

    [Required]
    public List<Equipment> Equipment { get; set; }

    [Required]
    public List<int> EquipmentIds { get; set; }

    [Required]
    public byte[] ProfileImage { get; set; }

设备是这样的

    [AutoIncrement]
    public int Id { get; set; }

    public EquipmentType EquipmentType { get; set; }

    [Required]
    public int EquipmentTypeId { get; set; }

    [Required]
    public string Name { get; set; }

我意识到知道 EquipmentIds 是它应该在设备 table 中检查的 ID 列表需要很多魔法,但由于 ServiceStack 的其他一切都是魔法,我给它一个尝试。

注意我已经缩短了一些模型,因为它们很长并且包含很多在这种情况下不需要的信息。

任何加入AutoQuery need to follow OrmLite's Reference Conventions