简体   繁体   English

使用Fluent API在Entity Framework中定义多对多关系

[英]Define relationship many to many in Entity Framework using Fluent API

I want to create the folllowing link table using fluent API. 我想使用流利的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? 是否可以将字段ID添加到表RolesVehicle中 ,这将是我的主键?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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