我正在努力构建一个提供单个最小值的linq查询。但是,我一直得到错误的最小值。我确定这是一个连接问题,但我无法获得一个外连接的工作。我已经尝试了一些基于其他职位的外部连接,但无法做任何工作。我不确定我需要外部连接来完成这项工作。我想我已经尝试过,我认为我可以组合每一个组合。Linq查询没有给出预期的结果
这里是我开始查询:
(from r in Results
join entry in Entries on r.EntryId equals entry.EntryId
join entryEvent in EntryEvents on entry.EntryId equals entryEvent.EntryId
join eswimmer in EntrySwimmers on entry.EntryId equals eswimmer.EntryId
where eswimmer.SwimmerId == 12027 && entryEvent.EventNumberId == 1233
select r.Time)
.Min();
外连接尝试:
from r in Results
join en in Entries on r.EntryId equals en.EntryId
join ev in EntryEvents on en.EntryId equals ev.EntryId into evJoined
join s in EntrySwimmers on en.EntryId equals s.EntryId into sJoined
from ev in evJoined.DefaultIfEmpty()
from s in sJoined.DefaultIfEmpty()
where (s.SwimmerId == 12027 && ev.EventNumberId == 1233)
select r.Time;
的问题是,我得到的所有结果最小值为游泳而不是该游泳者的最小值和特定事件。
的阶级结构是这样的:
结果
public int ResultId
public int EntryId
public ICollection<Entry> Entry
public int EntryEventId
public ICollection<EntryEvent> EntryEvent
public TimeSpan Time
项
public int EntryId
public ICollection<EntrySwimmer> EntrySwimmers
public Result Results
public ICollection<EntryEvent> EntryEvents
EntryEvents
public int EntryEventId
public int EventNumberId
public EventNumber EventNumbers
public int EntryId
public Entry Entry
EntrySwimmers
public int EntryId
public Entry Entries
public int SwimmerId
public Swimmer Swimmers
我还在学习关于linq,连接等等,所以感谢解释。先谢谢你!
首先在T-SQL中编写一个工作查询,然后从那里开始向后工作。 – Nkosi
我在SQL中得到了相同的结果。 – Wyatt
这个模特好吗? 'Entry'有许多'EntryEvents' *和*许多'EntrySwimmers'。你如何将游泳者连接到特定的'EntryEvent'? –