List<string> list = (from a in db.B_GAPMethod
where a.name == Gapname
select a.GAPMethodId).ToList();
foreach (var b in list)
{
var ifherb = db.B_GAPTemplate.Where(e => e.GAPMethodId == b).FirstOrDefault().herbId;
}
我要实现如果 if (ifherb == herbid)则进行下一步操作。否则继续循环如何实现
2 个解决方案
#1
如果查询到的数据满足条件则跳出循环否则继续循环
-》
foreach (var b in list)
{
var ifherb = db.B_GAPTemplate.Where(e => e.GAPMethodId == b).FirstOrDefault().herbId;
if (ifherb == herbid)
{
break;
}
}
-》
foreach (var b in list)
{
var ifherb = db.B_GAPTemplate.Where(e => e.GAPMethodId == b).FirstOrDefault().herbId;
if (ifherb == herbid)
{
break;
}
}
#2
.FirstOrDefault().
不存在记录会异常
不存在记录会异常
#1
如果查询到的数据满足条件则跳出循环否则继续循环
-》
foreach (var b in list)
{
var ifherb = db.B_GAPTemplate.Where(e => e.GAPMethodId == b).FirstOrDefault().herbId;
if (ifherb == herbid)
{
break;
}
}
-》
foreach (var b in list)
{
var ifherb = db.B_GAPTemplate.Where(e => e.GAPMethodId == b).FirstOrDefault().herbId;
if (ifherb == herbid)
{
break;
}
}
#2
.FirstOrDefault().
不存在记录会异常
不存在记录会异常