views:

25

answers:

0

I have been told that it's more than likely my database that is setup wrong causing the problems so below are my tables with key fields and queries.

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)
)

When I execute the following:

presentations = presentations.OrderBy(x => x.Speaker.FirstName);

The query generated looks like:

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]

The join should be:

LEFT    OUTER JOIN [Speakers] AS t1 ON ([t1].[Id] = [t0].[SpeakerId])

This is an urgent problem, can anyone help?

Related Questions:

Really appreciate some help.