我正在尝试在同一个表中添加类别之间的关系。我有一个
类别(ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT)
表和
CATEGORIES_CATEGORIES(ID INTEGER PRIMARY KEY AUTOINCREMENT, CATEGORIES_ID INTEGER NOT NULL,SUBCATEGORIES_ID INTEGER NOT NULL)
表。
我正在尝试将它们与Vici Coolstorage ORM一起绘制。我已经上课了
类别
[MapTo("CATEGORIES")]
public abstract class Category : CSObject<Category>
{
public abstract int Id { get; }
public abstract string Name { get; set; }
[ManyToMany("CATEGORIES_CATEGORIES", Pure = true)]
public abstract CSList<CategoryCategory> Subcategories { get; set; }
}
CategoryCategory类
[MapTo("CATEGORIES_CATEGORIES")]
public abstract class CategoryCategory : CSObject<CategoryCategory>
{
public abstract int Id { get; }
[ManyToOne(LocalKey = "CATEGORIES_ID", ForeignKey = "ID")]
public abstract Category Cat { get; set; }
[ManyToOne(LocalKey = "SUBCATEGORIES_ID", ForeignKey = "ID")]
public abstract Category SubCat { get; set; }
}
但我不能让它发挥作用。任何人都可以帮助我建立这种关系吗?
答案 0 :(得分:2)
您的映射表不应该是多对多关系的目标。
尝试这样的事情:
[ManyToMany("CATEGORIES_CATEGORIES",
LocalKey="ID", ForeignKey="ID",
LocalLinkKey="CATEGORIES_ID", ForeignLinkKey="SUBCATEGORIES_ID")]
public abstract CSList<Category> Subcategories { get; }