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

前端之家收集整理的这篇文章主要介绍了c# – 层次实体框架查询异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用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. @H_404_12@

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

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属性,会发生什么?@H_404_12@

猜你在找的C#相关文章