Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
previously i passed the single parameter now im trying to pass multiple values from the generic list .
I need to use where condition generic list column datas instead of value . i dont know how to use this.
List<RoleView> intRoleID 



var Rights = from user in main.Elements("Role")
                         where intRoleID == Convert.ToInt32(user.Element("RoleID").Value)
                      select new
                       {
                           RoleID = user.Element("RoleID").Value,
                           MenuID = user.Element("MenuID").Value,
                           Url = user.Element("Url").Value
                       };


What I have tried:

i tried do loop to construct the column values as string then pass it there
Posted
Updated 18-Sep-16 11:12am
Comments
Maciej Los 17-Sep-16 14:36pm    
Show us how you pass that multiple values onto list?

If I've understood you correctly, something like this should work:
C#
var Rights = from user in main.Elements("Role")
             where intRoleID.Contains(Convert.ToInt32(user.Element("RoleID").Value))
             select new
             {
                 RoleID = user.Element("RoleID").Value,
                 MenuID = user.Element("MenuID").Value,
                 Url = user.Element("Url").Value
             };
 
Share this answer
 
Comments
Karthik_Mahalingam 17-Sep-16 1:19am    
5!i guess correct,
if you rename the intRoleId to lstintRoleId it would be easier to understand
sencsk 19-Sep-16 1:34am    
thanks for ur comments . which you provided the soln is correct but my case i need soln2.
I'm not sure i've understood you correctly, but...

Seems, you want to filter List<RoleView> by passing list of id's to find. For such of requirement, you can use Where + Any methods. Take a look at example:
C#
void Main()
{

	List<Role> rules = new List<Role>();
	for (int i=1; i<=10; i++)
		rules.Add(new Role(i));
	
	int[] rules2find = new int[]{1,5,9};
	
	var filteredlist = rules
		.Where(x=>rules2find.Any(y=>x.RoleID ==y))
		.ToList();
	
	foreach(Role r in filteredlist)
	{
		Console.WriteLine(r.RoleID);
	}
        //returns rules with ID={1,5,9}
	
}

public class Role
{
	private int id = 0;
	
	public Role(int _id)
	{
		id = _id;
	}
	
	public int RoleID
	{
		get {return id;}
		set {id = value;}
	}
}


For further details, please see:
Enumerable.Where(TSource) Method (IEnumerable(TSource), Func(TSource, Boolean)) (System.Linq)[^]
Enumerable.Any(TSource) Method (IEnumerable(TSource), Func(TSource, Boolean)) (System.Linq)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900