不能將類型'System.Linq.IQueryable'隱式轉換爲'System.Collections.Generic.List'。存在明確的轉換(您是否缺少演員?)。我有我使用的各種表來獲取我的數據,我正在嘗試使用存儲庫模式和linq/lambda。例如將linq轉換爲lambda
public List<tblMenu> getmainmenusclass()
{
var UserInfo = GetUserInfo();
UserType = UserInfo[0].UserTypeID;
var menus = DataAccess.Menus.FindByExp(x => x.IsDeleted == false).ToList();
if (UserType == "E")
{
menus = menus.Where(x => x.IsDeleted == false).ToList();
}
現在我需要將下面的代碼轉換爲lambda而不使用。選擇並且一直未能找到替代方案。因爲我沒有使用IQueryable的
menus = DataAccess.Menus.FindByExp(Menus => ((Menus.IsDeleted == false) &&
(DataAccess.UserMenuMappings.FindByExp(UserMenuMapping => (UserMenuMapping.UserID == Global.CurrentProfile.UserID))
.Select(UserMenuMapping => new { MenuID = UserMenuMapping.MenuID }).Contains(new { MenuID = Menus.MenuID }) ||
DataAccess.RoleMenuMappings.FindByExp(RoleMenuMapping => DataAccess.UserRoleMappings.FindByExp(UserRoleMapping => (UserRoleMapping.UserID == Global.CurrentProfile.UserID))
.Select(UserRoleMapping => new { RoleID = UserRoleMapping.RoleID }).Contains(new { RoleID = RoleMenuMapping.RoleID }))
.Select(RoleMenuMapping => new { MenuID = RoleMenuMapping.MenuID }).Contains(new { MenuID = Menus.MenuID }))))
.Select(Menus => new { MenuID = Menus.MenuID, MenuName = Menus.MenuName });
你是什麼意思「我需要將下面的代碼轉換爲lambda」?該代碼已經使用lambdas。 –