2012-01-07 74 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来工作。

问候。