特定のオブジェクトのパブリック プロパティをドロップダウンに入力したいのですが、これはうまくいきました。しかし、ユーザーがドロップダウンから値を選択すると、DB テーブルの結果をその列でグループ化する必要があります。LINQ を使用してみましたが、リフレクション プロパティではなく、インスタンス変数プロパティによって明示的にグループ化する方法しかわかりません。これが私のメソッドです。渡されるパラメーターは、プロパティの文字列名です。たとえば、ユーザーが Customer.Country でグループ化する場合は「Country」になり、ユーザーが Customer.State でグループ化する場合は「State」になります。しかし、現時点では、LINQ クエリで渡された文字列値を使用する方法がわからないため、「状態」でグループ化するようにハードコーディングしています。
private void DisplayReportAction(string category)
{
if (!string.IsNullOrEmpty(category))
{
SelectedCategory = category;
_summaries.Clear();
foreach (var custGroup in _customerInterface.CustomerInterface.GetAllCustomers().GroupBy(c => c.State)
.Select(group => new
{
Category = group.Key,
Count = group.Count()
})
.OrderBy(x => x.Category))
{
_summaries.Add(new CustomerReportSummaryViewModel(custGroup.Category, custGroup.Count));
}
ReportVisibility = Visibility.Visible;
}
}