EDIT: This happen only on larger scale projects with repositories. Is there anybody using EF4 with CodeFirst approach and using repositories? Please advise me.
Hi. I
Try use this signature. I hope this worked.
public class Author
{
public virtual int AuthorId { get; set; }
public virtual string Name { get; set; }
private ICollection _books;
public virtual ICollection Books
{
get { return _books ?? (_books = new HashSet()); } // Try HashSet
set { _books = value; }
}
public void AddBook(Book book)
{
book.Author = this;
Books.Add(book);
}
}