如何在linq中包含哪个类 [英] How to include where class in linq

查看:63
本文介绍了如何在linq中包含哪个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下是我的代码

< blockquote  class  =   FQ>< div  class  =   FQA> Quote:< /   div  >   public   static 列表< OverallCompliance> GetOverallCompliance( string  str)
{
List< OverallCompliance> overall_compliance = new 列表< OverallCompliance>();
尝试
{
使用(BaseEntities entity = new BaseEntities())
{
overall_compliance = entity.mssp_eps_compliance_report
。选择(s = > ; new {s.ID,s.REPORT_TYPE,s.REPORT_DATE,s.COMPLIANT,s.NON_COMPLIANT})
.AsEnumerable()
。选择(x = > new OverallCompliance
{
id = int .Parse(x.ID.ToString()),
type = x.REPORT_TYPE,
date = x.REPORT_DATE,
compliant = int .Parse(x.COMPLIANT),
non_compliant = int .Parse(x.NON_COMPLIANT)
})。ToList();
}
}
catch (Exception ex){}
return overall_compliance;
} < / blockquote >





当从entity.entity.mssp_eps_compliance_report中获取值时

我需要过滤值通过使用str == s.REPORT_TYPE,然后我需要选择所有这些值..请帮忙。提前谢谢

解决方案

这就像你编写select write其中方法和使用条件与lambda表达式一样简单。





  public   static 列表与LT; OverallCompliance> GetOverallCompliance( string  str)
{
List< OverallCompliance> overall_compliance = new 列表< OverallCompliance>();
尝试
{
使用(BaseEntities entity = new BaseEntities())
{
overall_compliance = entity.mssp_eps_compliance_report
.Where(x => x.REPORT_TYPE == str)。选择(x =& gt; new OverallCompliance
{
id = int 。 Parse(x.ID.ToString()),
type = x.REPORT_TYPE,
date = x.REPORT_DATE,
compliant = int .Parse(x.COMPLIANT),
non_compliant = int .Parse(x.NON_COMPLIANT)
})。ToList();
}
}
catch (Exception ex){}
return overall_compliance;
} < / pre > < /跨度>


Hi,

Below is my code

<blockquote class="FQ"><div class="FQA">Quote:</div>public static List<OverallCompliance> GetOverallCompliance(string str)
        {
            List<OverallCompliance> overall_compliance = new List<OverallCompliance>();
            try
            {
                using (BaseEntities entity = new BaseEntities())
                {
                    overall_compliance = entity.mssp_eps_compliance_report
                        .Select(s => new { s.ID, s.REPORT_TYPE, s.REPORT_DATE, s.COMPLIANT, s.NON_COMPLIANT })
                        .AsEnumerable()
                        .Select(x => new OverallCompliance
                        {
                            id = int.Parse(x.ID.ToString()),
                            type = x.REPORT_TYPE,
                            date = x.REPORT_DATE,
                            compliant = int.Parse(x.COMPLIANT),
                            non_compliant = int.Parse(x.NON_COMPLIANT)
                        }).ToList();
                }
            }
            catch (Exception ex) { }
            return overall_compliance;
        }</blockquote>



When fectching the value from entity.entity.mssp_eps_compliance_report
I need to filter the value by using where str == s.REPORT_TYPE, and then I need to select all these values.. Please help. Thanks in advance

解决方案

It is as simple as you write select write Where method and use condition with lambda expression.


public static List<OverallCompliance> GetOverallCompliance(string str)
        {
            List<OverallCompliance> overall_compliance = new List<OverallCompliance>();
            try
            {
                using (BaseEntities entity = new BaseEntities())
                {
                    overall_compliance = entity.mssp_eps_compliance_report
                        .Where(x=>x.REPORT_TYPE==str).Select(x =&gt; new OverallCompliance
                        {
                            id = int.Parse(x.ID.ToString()),
                            type = x.REPORT_TYPE,
                            date = x.REPORT_DATE,
                            compliant = int.Parse(x.COMPLIANT),
                            non_compliant = int.Parse(x.NON_COMPLIANT)
                        }).ToList();
                }
            }
            catch (Exception ex) { }
            return overall_compliance;
        }</pre>


这篇关于如何在linq中包含哪个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆