列表到实体集合

发布于 2024-12-25 21:53:50 字数 510 浏览 1 评论 0原文

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

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

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

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

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

我现在得到的错误是:

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

有人经历过这个问题吗?

谢谢。

I've been trying to add some selected items from a multi-select listbox on my entry class.

After some research I found that this solution would work:

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

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

but even though it solved the first problem I was having I'm getting a new one now. One that I can't seem to find the solution... I even tried detaching the entity, but with no luck.

The error I get now is:

Requested operation is not allowed when the owner of this RelatedEnd is null. RelatedEnd objects that were created with the default constructor should only be used as a container during serialization.

have anyone been through this problem?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2025-01-01 21:53:50

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

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

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

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

问候。

I solved it a different way.

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

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

Needed a new List to work.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文