Atle Kristiansen
Atle Kristiansen

Reputation: 707

AutoQuery with ResponseDTO in ServiceStack

I have created an AutoQuery function in my API with the use of the following code.

[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; }
}

The CarDto looks like this

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; }
}

I was wondering if there are any specific values the IJoin looks for, because when I try to use this I get "Could not infer relationship between Car and Equipment"

Car looks like this.

    [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; }

Equipment looks like this.

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

    public EquipmentType EquipmentType { get; set; }

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

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

I realise that there would require alot of magic knowing that EquipmentIds is a list of Ids that it should check for in the Equipment table, but since everything else with ServiceStack is magic, I am giving it a try.

NB I have shortened some of the models because they are long and contains lots of information which is not needed in this case.

Upvotes: 1

Views: 32

Answers (1)

mythz
mythz

Reputation: 143339

Any joins in AutoQuery need to follow OrmLite's Reference Conventions.

Upvotes: 1

Related Questions