【发布时间】:2015-12-03 16:44:15
【问题描述】:
我有两张桌子:
People (~10000 Record)
PID Primary Key
PeopleCharater (~500000 Record)
OID Primary Key
PID Foreign Key
RecordDate(DateTime of the record is created)
它是一对多的关系,一个PID有多个OID。
我想选择与 Hashset(Of PID) 和 StartDate 和 EndDate 之间的 RecordDate 匹配的 OID 列表 棘手的部分是,应该包含
例子:
PeopleCharacter
OID PID RecordDate
a 1 2014-10-09
b 1 2015-12-10
c 1 2015-12-15
d 1 2016-02-25
如果 StartDate 是 2015-01-01 到 2015-12-31,则检索到的记录应该是 a b 和 c。
如何编写 LINQ 查询来检索记录?
我当前的代码:
Dim PIDHash as Hashset(Of PID)(~10000 PID)
db.Filter(Function(x) x.RecordDate >= StartDate andalso x.RecordDate <= EndDate andalso PIDHash.contains(x.PID)).
Union(??? another filter to select the greatest RecordDate < StartDate)
由于性能问题,必须限制从数据库检索的次数。接受存储过程解决方案。
【问题讨论】:
-
您正在检索 People 表的全部内容,然后将其发送回数据库以用作过滤器?
-
我从用户输入中获取整个 People 表,并检索符合条件的每个人字符。