1

我正在尝试在同一个表中添加类别之间的关系。我有一个

类别(ID 整数主键自动增量,名称文本)

表和

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; }
    }

但我不能让它工作。任何人都可以帮助我让这种关系发挥作用吗?

4

1 回答 1

2

您的映射表不应该是多对多关系的目标。

尝试这样的事情:

[ManyToMany("CATEGORIES_CATEGORIES", 
            LocalKey="ID", ForeignKey="ID",  
            LocalLinkKey="CATEGORIES_ID", ForeignLinkKey="SUBCATEGORIES_ID")]
public abstract CSList<Category> Subcategories { get; }
于 2013-03-03T21:48:09.313 回答