以非常簡單的術語,我想在某些情況下將字符串分配給變量。我試圖把if語句放在全局變量的linq語句的外部,但是然後它通過if /然後將字符串賦值給變量,然後在我的excel文件中爲每一行打印出來產生的。如果/然後在Linq聲明
讓我怎麼把類似這樣的
var status = "";
if(_db.Owners.Select(i => i.Item1) != null && _db.Owners.Select(i => i.Item2) == null)
{
status = "S";
}
到我的LINQ語句聲明說類似於這樣
return _db.Owners
.Select(owner => new
{
CustomerId = owner.Report.CustomerId,
IdType = status,//I want this statement to print that status S only where the statement is true
}
你只想與狀態項目= S的返回的集合,或者你只希望在那種情況下打印*? – BradleyDotNET
我不知道我是否正確 - 你只需要'Item1!= null'和'Item2 == null'的'owner'對象以狀態S打印?其他記錄怎麼樣 - 他們有什麼狀態? –