问题是“一个作者可能没有或有很多书,但一本书绝不是由两个或多个作者写的。”
public Author(Document cpf, string name, DateTime birthdate)
{
Cpf = cpf;
Name = name;
Birthdate = birthdate;
}
public Document Cpf { get; private set; }
public string Name { get; private set; }
public DateTime Birthdate { get; private set; }
// EF Relation
public Book Book { get; private set; }
public ICollection<Book> Books { get; private set; }
protected Author() { }
// 0 : N => Author : Books
builder.HasMany(c => c.Books)
.WithOne(b => b.Author)
.HasForeignKey(b => b.AuthorId);
public Book(Guid categoryId, Guid authorId, string title, DateTime releaseDate, BookIdentificator isbn)
{
CategoryId = categoryId;
AuthorId = authorId;
Title = title;
ReleaseDate = releaseDate;
Isbn = isbn;
}
public Guid CategoryId { get; private set; }
public Guid AuthorId { get; private set; }
public string Title { get; private set; }
public DateTime ReleaseDate { get; private set; }
public BookIdentificator Isbn { get; private set; }
public Category Category { get; private set; }
public Author Author { get; private set; }
// 1 : 1 => Books : Author
builder.HasOne(c => c.Author)
.WithOne(b => b.Book)
.HasForeignKey(b => b.AuthorId);
错误:无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型 BookManager.Catalog.Data