Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,

How can i apply a filter on "IEnumerable"? "GetTaskAllocatedOnFilter" property list any value can be null basis on that i need a data

Please help, also let know if you guys want any other information to proved me solution on this

What I have tried:

public class GetTaskAllocatedOnFilter
{
public Guid? Project_ID { get; set; }
public Guid? Emp_ID { get; set; }
public Guid? Task_ID { get; set; }
}
public IEnumerable<task_allocationmodel> GetTaskAllocatedList(GetTaskAllocatedOnFilter getOnFilter)
{
_DALTaskAllocation = new DALTaskAllocation();
DataTable taskAllocatedList = _DALTaskAllocation.GetTaskAllocatedList(getOnFilter);
IEnumerable<task_allocationmodel> IEtaskAllocationList = taskAllocatedList.AsEnumerable().Select(row => new Task_AllocationModel() {
Emp_ID = new Guid(row["Emp_ID"].ToString()),
Emp_Name = row["Emp_Name"].ToString(),
Hrs = Convert.ToInt16(row["Hrs"]),
Location = row["Location"].ToString(),
Location_ID = Convert.ToInt16(row["Location_ID"]),
Month = Convert.ToInt16(row["Month"].ToString()),
Project_ID = new Guid(row["Project_ID"].ToString()),
Project_Name = row["Project_Name"].ToString(),
Reporting_Manager = row["Reporting_Manager"].ToString(),
Task_ID = new Guid(row["Task_ID"].ToString()),
Total = Convert.ToInt16(row["Total"].ToString()),
Type_ID = Convert.ToInt16(row["Type_ID"].ToString()),
Year = Convert.ToInt16(row["Year"].ToString()),
Createddate = Convert.ToDateTime(row["Createddate"].ToString()),
CreatedBy = row["CreatedBy"].ToString()
});
if ((Guid.Empty == getOnFilter.Emp_ID && Guid.Empty == getOnFilter.Project_ID) && Guid.Empty != getOnFilter.Task_ID)

if ((Guid.Empty == getOnFilter.Emp_ID && Guid.Empty == getOnFilter.Task_ID) && Guid.Empty != getOnFilter.Project_ID)

if ((Guid.Empty == getOnFilter.Project_ID && Guid.Empty == getOnFilter.Task_ID) && Guid.Empty != getOnFilter.Emp_ID)

if ((Guid.Empty == getOnFilter.Project_ID && Guid.Empty == getOnFilter.Task_ID) && Guid.Empty != getOnFilter.Emp_ID)

return IEtaskAllocationList;
}
Posted
Updated 4-Feb-17 5:35am

1 solution

You can use the .Where extension method: Enumerable.Where(TSource) Method (IEnumerable(TSource), Func(TSource, Boolean)) (System.Linq)[^]:
C#
using System.Linq;
// Example: 
IEnumerable<int> old = new int[] { 0, 1, 2, 3 };
IEnumerable<int> _new = old.Where(x => x != 0);

In the above example, _new will contain all elements from old except 0: the predicate for x is x != 0. You can adapt this filtering example to your codebase.
 
Share this answer
 

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



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