简体   繁体   English

如何在列表中使用Linq过滤数据<object>

[英]How to filter data using Linq in List<object>

I am calling stored procedure to get data from database using Linq. 我正在调用存储过程以使用Linq从数据库获取数据。 This stored procedure is using more than one table to return result using join : 此存储过程使用多个表使用join返回结果:

public static List<classname> GetMediaTemp()
{
var medialist = (from m in Context.sp_Temp() select new classname
                                            {
                                               str_image = m.str_image,
                                                str_image_type = m.str_image_type,
                                                str_photodrawvideo = m.str_photodrawvideo,
                                            }).ToList();
if (medialist.Count > 0)
{
   return medialist
}
}

Everything working fine but now i have to filter data in this object list like on the calling end 一切工作正常,但现在我必须像调用端一样在此对象列表中过滤数据

List<classname> photoList = GetMediaTemp();//Here i want to filter list on the basis on str_photodrawvideo column.

Problem : 问题:

How i can perform this filter ? 我如何执行此过滤器?

Thanks in Advance. 提前致谢。 For more info please let me know. 有关更多信息,请让我知道。

you can do as below 你可以做如下

var objList = Context.sp_Temp().ToList();
var photoList = objList.Where(o=>o._int_previous == 1).ToList();

Or 要么

you can cast the object to Class which build the object list as below 您可以将object为Class,从而构建对象列表,如下所示

var photoList = 
   (from pht in objList 
     let x=>(sp_TempResult)pht
     where x._int_previous == 1 select pht).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM