簡體   English   中英

列出到EntityCollection

[英]List to EntityCollection

我一直在嘗試從輸入類的多選列表框中添加一些選定的項目。

經過一番研究,我發現此解決方案可行:

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

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

但是即使它解決了第一個問題,我現在也要擁有一個新的。 我似乎找不到解決方案的解決方案...我什至嘗試分離實體,但沒有運氣。

我現在得到的錯誤是:

當此RelatedEnd的所有者為null時,不允許請求的操作。 使用默認構造函數創建的RelatedEnd對象僅應在序列化期間用作容器。

有人遇到過這個問題嗎?

謝謝。

我用另一種方法解決了。

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

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

需要一個新的列表才能工作。

問候。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM