Hi, I’ve got this newbie “problem” with data returned from my table.
I have these two SQL table in my db:
that I have defined them with these models:
[Route("/customer", "GET")]
public class Customer
{
[PrimaryKey]
[AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public int? CustomerAddressId { get; set; }
[Reference]
public CustomerAddress PrimaryAddress { get; set; }
}
public class CustomerAddress
{
[PrimaryKey]
[AutoIncrement]
public int Id { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
}
and this interface:
public class CustomeServices : Service
{
public object Get(Customer request)
{
return Db.Select<Customer>();
}
}
I have this output:
[{"Id":1,"Name":"cust1","CustomerAddressId":1},
{"Id":2,"Name":"cust2","CustomerAddressId":2},
{"Id":3,"Name":"cust3","CustomerAddressId":3},
{"Id":4,"Name":"cust4","CustomerAddressId":4}]
but I was expecting something like that:
[{"Id":1,"Name":"cust1","PrimaryAddress":
{"Id":1,"AddressLine1":"add11","AddressLine2":"add12","City":"city1","State":"state1","Country":"country1"}
},
{"Id":2,"Name":"cust2","PrimaryAddress":
{"Id":2,"AddressLine1":"add21","AddressLine2":"add22","City":"city2","State":"state2","Country":"country2"}
},
{"Id":3,"Name":"cust3","PrimaryAddress":
{"Id":3,"AddressLine1":"add31","AddressLine2":"add32","City":"city3","State":"state3","Country":"country3"},
},
{"Id":4,"Name":"cust4","PrimaryAddress":
{"Id":4,"AddressLine1":"add41","AddressLine2":"add42","City":"city4","State":"state4","Country":"country4"}]
}]
What should I do? I’m expecting it wrong results?
Thank you.