如何在onienumerable上应用动态过滤器?

编程入门 行业动态 更新时间:2024-10-27 00:29:09
本文介绍了如何在onienumerable上应用动态过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 如何在IEnumerable上应用过滤器? GetTaskAllocatedOnFilter属性列表任何值都可以为null我需要一个数据 请帮忙,也知道你们是否想要任何其他信息来证明我的解决方案在这个 我尝试过: 公共类GetTaskAllocatedOnFilter { 公共指导? Project_ID {get;组; } 公共指导? Emp_ID {get;组; } 公共指导? Task_ID {get;组; } } public IEnumerable< task_allocationmodel> GetTaskAllocatedList(GetTaskAllocatedOnFilter getOnFilter) { _DALTaskAllocation = new DALTaskAllocation(); DataTable taskAllocatedList = _DALTaskAllocation.GetTaskAllocatedList(getOnFilter); IEnumerable< task_allocationmodel> IEtaskAllocationList = taskAllocatedList.AsEnumerable()。选择(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 [位置]。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()), 年= 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) 返回IEtaskAllocationList; }

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; }

推荐答案

您可以使用 .Where 扩展方法: Enumerable.Where(TSource)方法(IEnumerable(TSource),Func(TSource,Boolean))(System.Linq) [ ^ ]: You can use the .Where extension method: Enumerable.Where(TSource) Method (IEnumerable(TSource), Func(TSource, Boolean)) (System.Linq)[^]: using System.Linq;

// Example: IEnumerable<int> old = new int[] { 0, 1, 2, 3 }; IEnumerable<int> _new = old.Where(x => x != 0);

在上面的示例中, _new 将包含 old 中的所有元素,但 0 除外: 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.

更多推荐

如何在onienumerable上应用动态过滤器?

本文发布于:2023-11-15 05:52:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   动态   如何在   onienumerable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!