I am trying to use NPoco's fetchOneToMany method to map an object with a list of nested objects, following this link like so:
[TableName("sds_ingredients_ing")]
[PrimaryKey("ing_id")]
public class Ingredient
{
[Column(Name = "ing_id")]
public int Id { get; set; }
[Column(Name = "ing_cas")]
public string Cas { get; set; }
[Ignore]
public IList<IngredientLang> Ingredient_Lang;
}
[TableName("sds_ingredients_lang")]
[PrimaryKey("ing_id")]
public class IngredientLang
{
[Column(Name = "ing_id")]
public int Id { get; set; }
[Column(Name = "lang_id")]
public int LangId { get; set; }
[Column(Name = "Name")]
public string Name { get; set; }
}
And here is the query:
List<Ingredient> list = db.FetchOneToMany<Ingredient, IngredientLang>(x => x.Id,
@"SELECT ing.*,
lang.*
FROM SDS_INGREDIENTS_ING ing
LEFT JOIN SDS_INGREDIENTS_LANG lang
ON ing.ING_ID=lang.ING_ID");
Npoco returns the following error: No Property of type ICollection`1 found on object of type: Ingredient, which confuses me because the class Ingredient does have a property of type IList. We've tried List, IList, IEnumerable and pretty much every type of collection we could think of and none of them worked.
Do you have any idea what might be going wrong?
Ingredient_Lang
is not a property. its a field. If you make it a property it should work.