0

I used below code

 string userList = string.Join(",", db.UserRole.Where(p => p.FirmUserID == 1).Select(p => p.RoleID.ToString()));

userList values below,

1,12,17,33,76

I have also below string list

List<string> roleList = new List<string>();
roleList.add("14");
rolelist.add("33");
roleList.add("76");

How can i check userList includes roleList value and get matches value in entity framework ?

2
  • 1
    Is there any reason why you're keeping the user list as a single string rather than as a list? And any reason why you're using strings for values which look like they're all numbers? Commented Feb 24, 2015 at 14:49
  • not really if you can suggest matcihng for list i can apply on my side thanks for help and realize Commented Feb 24, 2015 at 14:49

1 Answer 1

2

First of all instead of converting your userList to string keep it as a List

List<string> userList = db.UserRole.Where(p => p.FirmUserID == 1).Select(p => p.RoleID.ToString()).Tolist();

To check if userList includes roleList

bool doesInclude = !roleList .Except(userList).Any();

to get the matches:

List<string> matches = userList.Intersect(roleList).ToList();

But if this is what you need to accomplish you'd better work sith integer types instead of string, because string comparison is more error prone (by the user).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.