私は次のLinqtoSQLを持っています:
var finalResults =
(from d in data
group d by new { d.LocationName, d.Year, d.Month, d.Denominator, d.Numerator } into groupItem
orderby groupItem.Key.Year, groupItem.Key.Month, groupItem.Key.LocationName
select new
{
IndicatorName = IndicatorName,
groupItem.Key.LocationName,
Year = string.Format("{0}", (int?)groupItem.Key.Year),
Month = string.Format("{0:00}", (int?)groupItem.Key.Month)
Numerator = groupItem.Sum(x => x.Numerator),
groupItem.Key.Denominator,
}).ToList();
問題は、YearとMonthの両方に空の文字列があることです。この場合、空の文字列を「使用不可」に置き換えたいと思います。私はこのような三元ステートメントを実行しようとしました:
Year = string.Format("{0}", (int?)groupItem.Key.Year) == "" ? "Not Available" : string.Format("{0}", (int?)groupItem.Key.Year),
Month = string.Format("{0:00}", (int?)groupItem.Key.Month) == "" ? "Not Available" : string.Format("{0:00}", (int?)groupItem.Key.Month),
私がやろうとしていたのは、「年(または月)に空の文字列がある場合は「使用不可」を表示し、そうでない場合は値を表示する」でした。
しかし、私はまだ失敗しているので、これは私がすることをしません
Assert.AreNotEqual( ""、endItem.Year);
Assert.AreNotEqual( ""、endItem.Month);
テスト。
何かアドバイス?