Hi Mou_kolkata,
Thank you for posting the problem in ADO.NET Entity Framework and LINQ to Entities.
>>see the 2nd set of code and tell me how EF manage to create many to many relation can be
established without 3rd table.
I don’t suppose that it is very accurate. For the
2nd set of code, it also created 3<sup>rd</sup> table by the following code.
modelBuilder.Entity<User>()
.HasMany(u => u.Roles)
.WithMany()
.Map(m => {
m.ToTable("UserRoles");// the code creates a table for managing the User table and Role table relationship
m.MapLeftKey("UserId");
m.MapRightKey("RoleId");
});
The 2<sup>nd</sup> set of code doesn’t only create 3<sup>rd</sup> model. The Fluent API configure a Many-to-Many relationship between User and Role.
If you would like to establish many to many relationship and the following link will give you some explanation, please refer to following link.
http://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx
If you have any other question for my reply, please feel free to contact me.
Best Regards,
Aaron.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.