列出到EntityCollection

时间:2012-01-07 02:20:36

标签: c# entity-framework-4 entitycollection

我一直在尝试从我的入门课程中的多选列表框中添加一些选定的项目。

经过一番研究后,我发现这个解决方案可行:

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

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

但即使它解决了我遇到的第一个问题,我现在又开始了。一个我似乎无法找到解决方案......我甚至尝试分离实体,但没有运气。

我现在得到的错误是:

  

当此RelatedEnd的所有者为null时,不允许请求的操作。使用默认构造函数创建的RelatedEnd对象应仅在序列化期间用作容器。

有没有人遇到过这个问题?

感谢。

1 个答案:

答案 0 :(得分:0)

我用不同的方式解决了它。

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

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

需要一个新的工作清单。

问候。

相关问题