【发布时间】:2014-09-28 17:32:02
【问题描述】:
我正在尝试使用 NPoco 的 fetchOneToMany 方法将对象映射到嵌套对象列表,如下this link:
[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 以及几乎所有我们能想到的集合类型,但都没有奏效。
你知道可能出了什么问题吗?
【问题讨论】:
-
反斜杠对 ing.\* 和 lang.\* 有什么作用?似乎是无效的 SQL 语法。
-
很抱歉。我是stackoverflow的新手,我使用[code]标签,在女巫之间,'*'字符由于某种原因不会显示。我通过在它之前添加 \ 来解决它,c++ 风格。然后我删除了 [code] 标签,因为我意识到你所要做的就是缩进,但我忘了删除反斜杠。现已修复。