已经看过其他一些答案,但不适用于这种情况。在vb.net中,以下是我试图实现的目标:
Dim query = From o In dbDS.gi_organisation
Join g In dbDS.gi_game On o.ID Equals g.DeveloperID Or o.ID Equals g.PublisherID
它不可编译。
有很多这样的解决方案(c#(:
var messages = from m in db.Message
join p in db.MessagePart
on new { m.ID, false } equals { p.MessageID, p.IsPlaintext }
但就我的一生而言,我无法将其应用于我的场景。有人能帮忙吗?
答案是完全放弃JOIN,并使用linq和lambda:的混合物
Dim query = From o In dbDS.gi_organisation
From g In dbDS.gi_game.Where(Function(x) x.DeveloperID = o.ID Or x.PublisherID = o.ID)
并控制您的外键中的任何null:
Dim query = From o In dbDS.gi_organisation
From g In dbDS.gi_game.Where(Function(x) (Not x.IsDeveloperIDNull AndAlso (x.DeveloperID = o.ID)) Or
(Not x.IsPublisherIDNull AndAlso (x.PublisherID = o.ID)))