如何在特定条件下使用Linq选择特定列

时间:2019-06-19 21:56:12

标签: c# sql linq

我正在执行两个存储过程并比较结果。每个存储的proc结果都在其自己的类中定义。

问题是如何使用定义的过滤器选择特定字段“ AreaId”?

var a = new List<aDrivingCursor>();
//execute stored proc 1
sp.Execute(out aDrivingCursor);

var b = new List<bDrivingCursor>();
//execute stored proc 2
sp2.Execute(out bDrivingCursor);

foreach (var temp in aDrivingCursor)
{
    int areaId = 0                       
    if (b.Any(s => s.Address1 == temp.Address1))
    {
        //This is where I'm having problem with
        areaId = Int32.Parse(b
            .Where(s => s.Address1 == a.Address1)
            .FirstOrDefault()
            .Select(o => o.AreaId));    
    }
}

这是我的课程:

class aDrivingCursor
{
    public String Address1 { get; set; }
}

class bDrivingCursor
{
    public int AreaId { get; set; }

    public String Address1 {get; set;}
}

0 个答案:

没有答案