LINQ 与 ManyToMany:基于多项选择的过滤
我是 C# 新手,必须在我的硕士论文中使用它。目前,我面临着一个对我来说有点复杂的问题。
我已经建立了一个具有多对多关系的数据库,如下所示:
Table Relay:
- id (PK)
- Name
- Input
Table ProtectionFunction:
- id (PK)
- ANSI
- IEC
- Description
Table RelayConfig (junction table)
- RelayID (PK)
- ProtFuncID (PK)
- TimeToSaturate
- Remanence
问题是,Relay
可以具有多个保护功能,并且对于每个保护功能,它都有特定的 TimeToSaturate
值代码>和<代码>剩磁。现在我想实现一个过滤器。用户可以通过DataGridView
中的复选框选择保护功能,并且ListBox
应该显示支持所有这些保护功能的所有Relay
。
我已经为我的项目创建了 LINQ-to-SQL 类。但现在我陷入困境,因为我不知道如何实现过滤。到目前为止我发现的所有 LINQ 命令都会为我提供一种保护功能的所有Relay
。
我真的希望你们中的一位能给我一个提示。
I am a newbe to C# and have to use it for my master thesis. At the moment, I am facing a problem that is a bit to complex for me.
I have set up a database with a many-to-many relationship like this:
Table Relay:
- id (PK)
- Name
- Input
Table ProtectionFunction:
- id (PK)
- ANSI
- IEC
- Description
Table RelayConfig (junction table)
- RelayID (PK)
- ProtFuncID (PK)
- TimeToSaturate
- Remanence
The thing is, a Relay
can have multiple protection functions, and for each it has specific values for TimeToSaturate
and Remanence
. Now I want to realize a filter. The user can select protection function via checkboxes in a DataGridView
and a ListBox
should show all Relay
s that support ALL of these protection functions.
I have already created the LINQ-to-SQL classes for my project. But now I am stuck because I don't know how to realize the filtering. All LINQ commands I have found so far would give me all Relay
s for one protection function.
I really hope one of you can give me a hint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更新
刚刚在 PredicateBuilder 页面上看到了这个:
Update
Just saw this on PredicateBuilder page:
如果从 RelayConfigs 开始会更容易。像这样的事情应该有效:
更新:
根据您的评论,以下内容应该有效,但是请监视生成的 SQL...
It's easier if you start from the RelayConfigs. Something like this should work:
UPDATE:
based on your comment, the following should work, however do monitor the SQL generated...
它不是特别有效,但这应该对你有用。
It's not especially efficient, but that should do the trick for you.
我已经在 Lightswitch 中完成了此操作,这是我的预处理查询:
希望有所帮助。
I have done this in Lightswitch, and here was my preprocess query:
Hope that helps.