2013-03-03 102 views
1

我試圖在同一個表中的類別之間添加關係。我有一個ManyToMany與同一張表的關係

類別(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一起映射。我做了類

Category類

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

但我不能使它發揮作用。任何人都可以幫助我獲得這種關係嗎?

+1

什麼行不通。請詳細說明。 – Cheesebaron 2013-03-03 21:37:36

回答

2

您的映射表不應該是多對多關係的目標。

嘗試這樣:

[ManyToMany("CATEGORIES_CATEGORIES", 
      LocalKey="ID", ForeignKey="ID", 
      LocalLinkKey="CATEGORIES_ID", ForeignLinkKey="SUBCATEGORIES_ID")] 
public abstract CSList<Category> Subcategories { get; } 
+0

謝謝,現在它工作:) – evilone 2013-03-04 04:44:12