2013-02-28 83 views
0

我有一個移動應用程序,我試圖利用windows phone數據庫。 但是我遇到了一個小問題。Linq to SQL多對多關係,使用集合

這是我到目前爲止。

[Table] 
public class CollectionManager 
{ 
    [Column(IsPrimaryKey = true)] 
    public int FilmID { get; set; } 

    [Column(IsPrimaryKey = true)] 
    public int CollectionID { get; set; } 

    private EntityRef<FilmData> film; 
    [Association(ThisKey = "FilmID", OtherKey = "ID", Storage = "film")] 

    public FilmData Film{ get { return film.Entity; } set { film.Entity = value; } } 

    private EntityRef<Collection> collection; 
    [Association(ThisKey = "CollectionID", OtherKey = "ID", Storage = "collection")] 

    public Collection Collection { get { return collection.Entity; } set { collection.Entity = value; } } 
} 


[Table] 
public class FilmData 
{ 
    [Column(IsPrimaryKey = true)] 
    public int FilmID { get; set; } 

    [Association(ThisKey = "ID", OtherKey = "FilmID")] 
    public EntitySet<CollectionManager> CollectionManager { get; set; } 
} 


[Table] 
public class Collection 
{ 
    [Column(IsPrimaryKey = true)] 
    public int CollectionID { get; set; } 

    [Association(ThisKey = "ID", OtherKey = "CollectionID ")] 
    public EntitySet<CollectionManager> CollectionManager { get; set; } 
} 

因此,這些都是我的3個表,但是我很努力

  • 電影添加到收藏
  • 獲取集合中的所有影片。

我非常感謝任何幫助,非常感謝您花時間閱讀本文!

回答

0

看起來你有你的EntitySet<>屬性倒退。你有一個FilmData類,有很多Collection和你的Collection類有很多CollectionManager。如果你想添加FilmDataCollection那麼你的Collection應該有很多FilmData