WCF 数据服务多对多关系
我有一个包含用户和角色表的数据库。它们之间的关系是多对多,我有一个联结表UserRole。
我使用实体框架使用此配置将其映射到我的对象模型:
modelBuilder.Entity<User>()
.HasMany(u => u.Roles)
.WithMany(r => r.Users)
.Map(m => m.ToTable("UserRole")
.MapLeftKey("UserId")
.MapRightKey("RoleId"));
这按预期工作,但现在我需要使用 OData 和 Powerpivot 将其公开给 Excel。但由于导入到 Powerpivot 时关系会丢失,因此我还需要公开联结表,以便可以在 Powerpivot 内重新创建关系。
我知道我需要创建一个新实体 UserRole,但我不确定如何配置映射。
有人有什么建议吗?
I have a database with tables for users and roles. The relationship between them is many-to-many and I have a junction table UserRole.
I use Entity Framework to map this to my object model using this configuration:
modelBuilder.Entity<User>()
.HasMany(u => u.Roles)
.WithMany(r => r.Users)
.Map(m => m.ToTable("UserRole")
.MapLeftKey("UserId")
.MapRightKey("RoleId"));
This works as expected but now I need to expose this to Excel using OData and Powerpivot. But since the relationships are lost when imported into Powerpivot I also need to expose the junction table so that I can recreate the relationship inside Powerpivot.
I understand that I need to create a new entity, UserRole but I am not sure how to configure the mapping.
Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论