sql - Need to compare which user is logged in to determine which information to show -
it's vendor page multiple users having different roles. right it's 2 user types, , have boolean method uses linq sql check if it's user made changes vendor. error i'm getting sequence returns multiple.
public static bool booluser1(string user) { bool user1bool = false; if (user == string.empty) { return false; } if (user != null) { var context = new rempscodatacontext(); string user1 = (from u in context.vendors u.user1_info_edit_user == user select u).singleordefault().user1_info_edit_user; if (user1 == user) user1bool = true; } return user1bool; }
well singleordefault throw exception if there more 1 element in sequence.
returns element of sequence, or default value if sequence empty; method throws exception if there more 1 element in sequence.
perhaps filter should more specific. iterate on entire sequence value want or try using firstordefault(), may not return correct result.
more on differences between singleordefault() , firstordefault() here:
linq: when use singleordefault vs. firstordefault() filtering criteria
Comments
Post a Comment