相关疑难解决方法(0)

Linq To Entities - 如何过滤子实体

我有实体GroupUser.
Group实体拥有Users财产是用户的列表.
用户有一个名为的属性IsEnabled.

我想编写一个返回Groups 列表的linq查询,该列表只包含Users IsEnabled为true 的s .

例如,对于类似下面的数据,
AllGroups
组A
用户1(IsEnabled = true)
用户2(IsEnabled = true)
用户3(IsEnabled = false)

B组
用户4(IsEnabled = true)
用户5(IsEnabled = false)
用户6(IsEnabled = false)

我想得到
FilteredGroups
A组
用户1(IsEnabled = true)
用户2(IsEnabled = true)

B组
用户4(IsEnabled = true)

我尝试了以下查询,但Visual Studio告诉我
[不能将属性或索引器'用户'分配给它 - 它是只读的]

FilteredGroups = AllGroups.Select(g => new Group()
                    {
                        ID = g.ID,
                        Name = g.Name,
                        ...
                        Users = g.Users.Where(u …
Run Code Online (Sandbox Code Playgroud)

linq linq-to-entities entity-framework wcf-ria-services

14
推荐指数
2
解决办法
2万
查看次数