在linq查询中嵌入if语句

时间:2019-05-20 19:49:25

标签: c# entity-framework linq

我正在尝试将以下代码压缩为一个select语句。这可能吗?

if (atcCode.HasValue)
{
    primaryOcc = (from f in db.aopFactor
                  where f.atcCode == atcCode
                  where f.endingDate == null
                  select f.primaryOccupancyID).FirstOrDefault();
}
var factorTable = (from f in db.aopFactor
                    where f.factorTypeID == factorType
                    where f.endingDate == null
                    where f.primaryOccupancyID == primaryOcc
                    select new { f.factorID, f.factorDescription }).ToDictionary(x => x.factorID, y => y.factorDescription);

0 个答案:

没有答案