简体   繁体   中英

Define relationship many to many in Entity Framework using Fluent API

I want to create the folllowing link table using fluent API.

HasMany(u => u.VehicleGroups).WithMany().Map(m =>
            {
                m.MapLeftKey("RoleId");
                m.MapRightKey("VehicleGroupId");
                m.ToTable("RolesVehicle");
            });

Is it possible to add the field Id to table RolesVehicle which will be my primary key?

是的,但是只能通过创建单独的实体RolesVehicle ,该实体具有您的RolesVehicles实体以及所需的任何其他字段的键和导航属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM