2012-01-07 72 views
0

我一直試圖從我的入門級的多選列表框中添加一些選定的項目。List to EntityCollection

經過一番研究,我發現,這個解決方案將工作:

EntityCollection<Publisher> entityCollection = new EntityCollection<Publisher>(); 

foreach (Publisher pub in this.publishersLst.SelectedItems) 
{ 
    entityCollection.Attach(pub); 
} 

但即使它解決了我在我得到一個新的,現在第一個問題。一個我似乎無法找到解決方案...我甚至試圖分離實體,但沒有運氣。

我現在得到的錯誤是:當這個RelatedEnd的主人是空

請求的操作是不允許的。使用默認構造函數創建的RelatedEnd對象只能在序列化期間用作容器。

有沒有人通過這個問題?

謝謝。

回答

0

我解決了它不同的方式。

  entry.Publishers = new EntityCollection<Publisher>(); 

      foreach (Publisher item in this.publishersLst.SelectedItems) 
      { 
       entry.Publishers.Add(item); 
      } 

需要一個新的List來工作。

問候。