OK、私はこれで頭を壁にぶつけています ;-)
データベース内の Address、Customer、および CustomerType という名前のテーブルを指定して、顧客に関する概要情報を組み合わせて表示したいので、これら 2 つのテーブルを結合して特定の結果を取得するクエリを作成します。
var customers = (from c in tblCustomer.All()
join address in tblAddress.All() on c.Address equals address.AddressId
join type in tblCustomerType.All() on c.CustomerType equals type.CustomerTypeId
select new CustomerSummaryView
{
CustomerName = c.CustomerName,
CustomerType = type.Description,
Postcode = address.Postcode
});
return View(customers);
CustomerSummaryView は単純な POCO です
public class CustomerSummaryView
{
public string Postcode { get; set; }
public string CustomerType { get; set; }
public string CustomerName { get; set; }
}
何らかの理由で、これは機能しません。CustomerSummaryView の結果の IEnumerable リストを取得します。各レコードには顧客名と郵便番号がありますが、顧客タイプ フィールドは常に null です。
さまざまなデータベース テーブルと投影されたクラスを使用して、この問題を数回再現しました。
誰でもアイデアはありますか?