有人告诉我,很可能是我的数据库设置错误导致了问题,所以下面是我的带有关键字段和查询的表。
CREATE TABLE Presentations (
Id INT NOT NULL IDENTITY(1, 1),
SpeakerId INT NOT NULL,
CONSTRAINT PK_Presentations PRIMARY KEY (Id),
CONSTRAINT FK_Presentations_Speaker FOREIGN KEY (SpeakerId) REFERENCES Speakers (Id)
)
CREATE TABLE Speakers (
Id INT NOT NULL IDENTITY(1, 1),
CONSTRAINT PK_Speakers PRIMARY KEY (Id)
)
当我执行以下操作时:
presentations = presentations.OrderBy(x => x.Speaker.FirstName);
生成的查询如下所示:
SELECT [t0].[Description], [t0].[EventId], [t0].[Id], [t0].[PresentedOn],
[t0].[Slug], [t0].[SpeakerId], [t0].[Title], [t0].[Url]
FROM [Presentations] AS t0
LEFT OUTER JOIN [Speakers] AS t1 ON ([t1].[Id] = [t0].[Id])
WHERE ([t1].[FirstName] LIKE 'B' + '%')
ORDER BY [t1].[FirstName]
连接应该是:
LEFT OUTER JOIN [Speakers] AS t1 ON ([t1].[Id] = [t0].[SpeakerId])
这是一个紧迫的问题,有人可以帮忙吗?
相关问题:
非常感谢一些帮助。