Entity Filter child without include
Posted
by
Lic
on Stack Overflow
See other posts from Stack Overflow
or by Lic
Published on 2013-10-25T08:59:29Z
Indexed on
2013/10/25
9:55 UTC
Read the original article
Hit count: 197
i'm a C# developer and i have a trouble with Entity Framework 5.
I have mapped my database with Entity using the default code generation strategy. In particolar there are three classes: menus, submenus and submenuitems. The relationships about three classes are: one menu -> to many submenus one submenu -> to many submenuitems.
All classes have a boolean attribute called "Active".
Now, i want to filter all the Menus with the SubMenus active, and the SubMenus with the SubMenuItems active.
To get this i've tried this:
var tmp = _model.Menus.Where(m => m.Active)
.Select =>
new
{
Menu = x,
SubMenu = x.SubMenus.Where(sb => sb.Active)
.Select(y =>
new
{
SubMenu = y,
SubMenuItem = y.SubMenuItems.Where(sbi => sbi.Active)
})
})
.Select(x => x.Menu).ToList();
But didn't work.
Someone can help me?
Thank you for your help!
© Stack Overflow or respective owner