コンストラクタで "ハッシュセット"を使用する場合と使用しない場合のクラスの作成の違いを知りたいと思います。エンティティフレームワークでハッシュセットを使用する
public class Blog
{
public int Id { get; set; }
public string Title { get; set; }
public string BloggerName { get; set;}
public virtual ICollection<Post> Posts { get; set; }
}
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public DateTime DateCreated { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public ICollection<Comment> Comments { get; set; }
}
または、このようなモデルを作成することができます:
1は、このようなモデルをレコード生成することができ、コードの最初のアプローチ(4.3)を使用して
public class Customer
{
public Customer()
{
BrokerageAccounts = new HashSet<BrokerageAccount>();
}
public int Id { get; set; }
public string FirstName { get; set; }
public ICollection<BrokerageAccount> BrokerageAccounts { get; set; }
}
public class BrokerageAccount
{
public int Id { get; set; }
public string AccountNumber { get; set; }
public int CustomerId { get; set; }
}
HashSetのは、ここで何をしているのですか?
私は最初の2つのモデルでもハッシュセットを使用する必要がありますか?
ハッシュセットの適用を示す記事はありますか?
私は完全に同意します。ほとんどの場合、 'HashSet' *は最も自然なフィットです。 –
ハッシュセットはまだEF6.xでは正しいようです。ネイティブに、EFは型のdb-first作成時にもこの正確な方法でハッシュセットを使用します。 –