I am new to Entity Framework and trying to figure it out. I have created a database that is not very complicated. There are about 7 tables and 3 of them are mapping tables for linking one table record to another. The example I use here is the following:
Table user
Table role
Table: UserRole
Foreign keys are displayed in my database. When I create a new Entity model in VS 2008, the diagram seems to be correct, but does not create a table for the UserRole table. The relationship is displayed as βPlenty for many" between the user and the role.
, , , , . , UserRole, , . :
ObjectQuery<Role> roles = context.Roles;
Role role = context.Roles.Where(c => c.RoleName == "Subscriber").First();
User user = new User
{
DisplayName = "TestCreate2",
Email = "test@test.com",
Password = "test"
};
context.AttachTo("Roles", role);
user.Roles.Add(role);
context.AddToUsers(user);
context.SaveChanges();
, :
EntitySet 'UserRoles', DefiningQuery, .
xml, UserRole:
<EntitySet Name="UserRoles" EntityType="RememberTheJourneyModel.Store.UserRoles" store:Type="Tables" store:Schema="dbo" store:Name="UserRoles">
<DefiningQuery>SELECT
[UserRoles].[Role_id] AS [Role_id],
[UserRoles].[User_id] AS [User_id]
FROM [dbo].[UserRoles] AS [UserRoles]</DefiningQuery>
</EntitySet>
, , , . , , UserRole, , .
google , , , , . , , EF , , , . , . ( SQL SERVER 2005 EXPRESS) ? , xml, . .