Fetch Linq to Entity result directly into Datatable
I am trying to make dynamic menu using Linq and entity. I wants to add
query result directly into datatable. select query (as shown below) throws
an exception. Exception:
LINQ to Entities does not recognize the method 'System.Data.DataRow
LoadDataRow(System.Object[], Boolean)' method, and this method cannot be
translated into a store expression
Is there alternative? Here below is my code.
DataTable dtMenu = new DataTable();
dtMenu.Columns.Add("MenuName", typeof(string));
dtMenu.Columns.Add("SubMenuName", typeof(string));
dtMenu.Columns.Add("FileName", typeof(string));
var menuItems = (from vUser in dbMenu.VirtualUserMenuMaps
join menu in dbMenu.MenuMasters on vUser.MenuId equals menu.MenuId
join subMenu in dbMenu.SubMenuMasters on vUser.SubMenuId equals
subMenu.SubMenuId
where vUser.VirtualId == virtualId
orderby menu.MenuId, subMenu.DisplayOrder
select dtMenu.LoadDataRow(
new object[] { menu.MenuName, subMenu.SubMenuName, subMenu.FileName },
false));
No comments:
Post a Comment