我有一个“菜单”表,其中有一个 ParentId 列。我的 LINQ 查询就在下面。
public IEnumerable<MenuTableObject> GetMenus ( int? parentId ) {
var result = ( from m in _db.Menus
join ml in _db.MenuLanguages on m.Id equals ml.MenuId
join l in _db.Languages on ml.LanguageId equals l.Id
where l.Code == Thread.CurrentThread.CurrentCulture.Name
&& m.ParentId == ( parentId.HasValue ? parentId : null )
select new MenuTableObject {
Action = m.Action,
Controller = m.Controller,
Id = m.Id,
Title = ml.Title,
SubMenus = this.GetMenus( m.Id )
} );
return result;
}
这是 MenuTableObject 类。
public class MenuTableObject {
public int Id { get; set; }
public string Title { get; set; }
public string Controller { get; set; }
public string Action { get; set; }
public IEnumerable<MenuTableObject> SubMenus { get; set; }
}
这是我在下面得到的例外。
LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1[IstanbulHairCenter.Data.Service.MenuTableObject] GetMenus(System.Nullable`1[System.Int32])' method, and this method cannot be translated into a store expression.
我该怎么做才能克服这个问题?