加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 层次实体框架查询异常

发布时间:2020-12-15 04:03:30 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Entity Framework构建一个分层收集 – 请参阅下面的查询 – 给定公司中的每个成员都有一个父成员 – 但是当尝试执行此操作时,我会收到以下异常: System.NotSupportedException: The type ‘Member’ appears in two structurally incompatibl
我正在尝试使用Entity Framework构建一个分层收集 – 请参阅下面的查询 – 给定公司中的每个成员都有一个父成员 – 但是当尝试执行此操作时,我会收到以下异常:

System.NotSupportedException: The type
‘Member’ appears in two structurally
incompatible initializations within a
single LINQ to Entities query. A type
can be initialized in two places in
the same query,but only if the same
properties are set in both places and
those properties are set in the same
order.

如果我删除ParentMember分配它的工作 – 任何关于发生什么的想法?

return from c in _Entities.Company
               where c.Deleted == false
                select new Member()
                {
                    Name = c.Name,ParentMember = new Member() 
                    {
                        Name = c.ParentMember.Name
                    }
                };

解决方法

我还没有尝试过这个,但错误信息给你一个线索:你不是在两个地方按相同的顺序设置相同的属性.

如果您尝试在外部Member()上设置ID属性,会发生什么?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读