将实体框架与SQL Server多对多关系使用
不知道如何在此处使用“显示事物”的高级功能,因此请原谅;-)
数据库结构
User --> UserOwnerR <-- Owner
也是我有几个支持结构(例如,属于特定所有者的地址)。
我需要找到特定用户可以访问的所有地址,因为它属于/许多所有者,但是不是地址,用户与谁具有所有者关系。
Do not know how to use the advanced features of displaying thing here, so please excuse ;-)
The database structure is
User --> UserOwnerR <-- Owner
Also I have several support structures (ex. addresses belonging to a specific owner).
I need to find all addresses to whom a specific user has access because it belongs to on/many owners, but not addresses to whom the user have a owner relation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
N:M关系可以在没有EF Core 5+中的联接表的情况下实现。
n:m relations can be realized without a join table in EF Core 5+.
您没有指定您使用EF代码的第一种方法(基于C#类生成架构)或数据库First方法(从数据库表中生成C#类)或无(手动设置您的实体)。
如果您能够手动更改课程,则可以添加导航属性。这些可能看起来像这样:
现在您可以在将这些桌子连接在一起的同时放置条件。将基于SQL语法的查询选项与LINQ一起使用,因为以这种方式连接表更容易。您可能想看看
You did not specify wether you’re using ef Code first approach (you generated your Schema based on c# classes) or database first approach (generate c# classes from database tables) or none of those (manually set up your entities).
If you are able to change your classes manually, you might add navigation properties. Those might look like this:
Now you are able to place conditions while joining those tables together. Use the sql syntax based query option with linq, as it’s easier to connect your tables that way. You might want to take a look at Entity Framework Join 3 Tables to construct your individual query.