-1

I want to use select query using linq to list.

in fallowing code userDtls is an list & Common.UserRightVal is an enum variable

userDtls = _userService.GetById(id);
var permission = from udtls in userDtls[0].userRightList 
where udtls.object_name == "Person" && 
(udtls.user_right   == (int)Common.UserRightVal.update
|| udtls.user_right == (int)Common.UserRightVal.add_update_delete_read 
|| udtls.user_right == (int) Common.UserRightVal.allRight)select udtls;

Here I want to check permission details for user. My question is if 'where' condition is getting false then also permission variable is showing default records as shown by userDtls list.

4

1 回答 1

0

感谢每一位的回复。我得到了答案,就在这里。

 var permission=(dynamic) null;
 permission = (from udtls in userDtls[0].userRightList
               where udtls.object_name.Contains(objectType) &&
               (udtls.user_right == (int)Common.UserRightVal.readAll
               || udtls.user_right == (int)Common.UserRightVal.read_readAll 
               || udtls.user_right == (int)Common.UserRightVal.add_update_delete_read
               || udtls.user_right == (int)Common.UserRightVal.allRight)
               select udtls).FirstOrDefault();
于 2013-11-18T09:24:10.533 回答