私のプロジェクトでは、2 つのクラスProductCategory
とProduct
.
public class ProductCategory
{
[Key]
public int CategoryId { get; set; }
[Required]
public string CategoryName { get; set; }
public ObservableCollection<Product> Products { get; set; }
}
public class Product{
[Key]
public int ProductId { get; set; }
[Required]
public string ProductName { get; set; }
[Required]
public int CategoryId { get; set; }
public virtual ProductCategory ProductCategory { get; set; }
}
私の UI には、カテゴリの下に製品を作成するためのフォームがあります。フォームには 2 つの ComboBox が含まれています。1 つは製品 ID 用で、もう 1 つはカテゴリ用です (値メンバー - カテゴリ ID、表示メンバー - カテゴリ名)。製品名用の別のテキスト ボックス。そして、製品をカテゴリ名とともに表示するための ListView。
私の質問は; これらのフィールドを含むオブジェクト コレクションを取得したい (ListView に表示するため)。
ProductID, ProductName, CategoryID, CategoryName
このことの正しい方法を教えてください。
ありがとう。