Entity Framework object link summary, entityframework
When I first started using the Entity Framework, I had to take some "pain-free" detours because I had not calmed down to clarify the relationship. Currently, our projects are all using the Entity Framework, so as to prevent others from having to go through a "pain-free" detour. So I made up my mind to "clarify the relationship" and "write a blog ". Writing a blog can help you solve the problem completely and avoid the waste of half-way. When I write these articles, I have a deeper understanding of the problem.
Let's learn from each other. Through this summary, we will take a hot dive into our understanding of the relationship between EF entities, which may lead to new gains. The same is true for our feelings. When feelings get cold, don't forget to go back to the hot pot.
ModelBuilder. Entity <BlogSite> ()
. HasRequired (B => B. BlogUser)
. Withtasks ()
. HasForeignKey (B => B. UserID );
B) bidirectional one-to-one (article link)
Class diagram:
ModelBuilder. Entity <BlogSite> ()
. HasRequired (B => B. BlogUser)
. Withtasks ()
. HasForeignKey (B => B. UserID );
ModelBuilder. Entity <BlogUser> ()
. HasRequired (u => u. BlogSite)
. Withtasks ()
. HasForeignKey (u => u. BlogID );
2. one-to-many relationship (article link)
Class diagram:
ModelBuilder. Entity <BlogSite> ()
. HasMany (B => B. BlogPosts)
. WithRequired (p => p. BlogSite );
3. Multi-to-many relationship (article link)
Class diagram:
ModelBuilder. Entity <BlogPost> ()
. HasMany (B => B. Categories)
. Withuploads (c => c. BlogPosts)
. Map
(
M =>
{
M. MapLeftKey ("BlogPostID ");
M. MapRightKey ("CategoryID ");
M. ToTable ("BlogPost_Category ");
}
);