LoWii LoWii - 1 year ago 112
SQL Question

NPoco fetchOneToMany error

I am trying to use NPoco's fetchOneToMany method to map an object with a list of nested objects, following this link like so:

public class Ingredient
[Column(Name = "ing_id")]
public int Id { get; set; }
[Column(Name = "ing_cas")]
public string Cas { get; set; }
public IList<IngredientLang> Ingredient_Lang;

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.*,
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?

Answer Source

Ingredient_Lang is not a property. its a field. If you make it a property it should work.