我正在尝试使用 NPoco 的 fetchOneToMany 方法将对象映射到嵌套对象列表,如下所示:
[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; }
}
这是查询:
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 返回以下错误:No Property of type ICollection`1 found on object of type: Ingredient,这让我感到困惑,因为类 Ingredient 确实具有 IList 类型的属性。我们已经尝试过 List、IList、IEnumerable 以及几乎我们能想到的所有类型的集合,但它们都不起作用。
你知道可能出了什么问题吗?