私は、多対多の関係ではHashSetののEX多対多の関係でHashSetが必要なのはなぜですか?
this.Supplier = new HashSet<supplier>();
を使用する多くのチュートリアルを発見しました。私は上記のコードをテストし、
public xxxx()
{
this.xxxx = new HashSet<xxxx>();
}
を削除した場合でも、SOMのチュートリアルが
public partial class Product
{
public Product()
{
this.Supplier = new HashSet<supplier>();
}
public long ProductID { get; set; }
public string ProductName { get; set; }
//navigation property to Supplier
public virtual ICollection<supplier> Supplier { get; set; }
}
public partial class Supplier
{
public Supplier()
{
this.Product = new HashSet<product>();
}
public long SupplierID { get; set; }
public string SupplierName { get; set; }
// navigation property to Product
public virtual ICollection<product> Product { get; set; }
}
(無多かれ少なかれ)HashSetのせずに以下のコードを使用していない私はまだ関連付けテーブルを持って、多対多関係。
なぜHashSetが必要ですか?両方のテーブルモデルでICollection
で定義された
その関係を定義するナビゲーションプロパティ( 'ICollection')です。コンストラクタ内のコードは初期化していますので、 'null ' –