Reputation: 401
Let's say I have the following three tables:
public class Book
{
public int Id { get; set; }
public string Title { get; set; }
public virtual ICollection<BookAuthor> BookAuthors { get; set; }
}
public class Author
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<BookAuthor> AuthorBooks { get; set; }
}
public class BookAuthor
{
public int Id { get; set; }
public int BookId { get; set; }
public Book Book { get; set; }
public int AuthorId { get; set; }
public Author Author { get; set; }
}
with the following mapping configuration:
public BookAuthorConfiguration()
{
// BookAuthor has a composite key:
HasKey(a => new { a.BookId, a.AuthorId });
// BookAuthor has 1 Book, Books have many BookAuthor records
HasRequired(a => a.Book)
.WithMany(s => s.BookAuthors)
.HasForeignKey(a => a.BookId)
.WillCascadeOnDelete(false);
// BookAuthor has 1 Author, Author have many BookAuthor records
HasRequired(a => a.Author)
.WithMany(p => p.AuthorBooks)
.HasForeignKey(a => a.AuthorId)
.WillCascadeOnDelete(false);
}
What I would like to do now, is to create a new book and a new registry in my junction BookAuthor table, I have no clue what breeze does automaticly and what i have to do myself.
If Author is already created, do I create two new entities, Book and BookAuthor, set the properties of the BookAuthor(BookId, AuthorId, Book, Author), then push the BookAuthors array of new created Book entity or am I over doing it?
I hope i provided you with enough information, if not let me know what is missing.
Thanks in advance!
Upvotes: 0
Views: 77
Reputation: 17863
Breeze does not support "many to many" so you have to expose the junction table as an entity in its own right. EF will force this for you because you added a property (Id
) other than the FKs that support the m-to-m relationship.
You'll have to manage that junction entity yourself on the Breeze client.
There is a popular request for Breeze support of m-to-m in User Voice. That said, we are not working on it and I have expressed my doubts about the value of attempting it.
Search StackOverflow for "Breeze" and "many to many" and you'll find lots of discussion.
Upvotes: 1