This is a migrated thread and some comments may be shown as answers.
INNER JOIN not being generated
1 Answer 22 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Top achievements
Rank 2
MotoSV asked on 26 Oct 2012, 12:37 PM

I am using the latest version of OpenAccess and when running the following LINQ query...
( from user in domainModel.Users
  join company in domainModel.Companies on user.Id equals company.UserId
  where user.UserName == userName
  select company ).FirstOrDefault()

...I get the following SQL statements reported in the SQL Profiler...
SELECT  TOP(@__TAKE) b.[Id] AS COL1 FROM [User] a JOIN [Company] AS b ON (a.[Id] = b.[UserId]) WHERE a.[UserName] = ''
SELECT [Name] AS COL1, [Synopsis] AS COL2, [UserId] AS COL3, [UserId] AS COL4, [WebsiteUrl] AS COL5 FROM [Company] WHERE [Id] = @p0

When I run the same query using the Entity Framework I get...
[Extent2].[Id] AS [Id],
[Extent2].[UserId] AS [UserId],
[Extent2].[Name] AS [Name],
[Extent2].[Synopsis] AS [Synopsis],
[Extent2].[WebsiteUrl] AS [WebsiteUrl]
FROM  [dbo].[User] AS [Extent1]
INNER JOIN [dbo].[Company] AS [Extent2] ON [Extent1].[Id] = [Extent2].[UserId]
WHERE N'' = [Extent1].[UserName]

Can anyone tell me why I get two different SQL statements?



1 Answer, 1 is accepted

Sort by
Viktor Zhivkov
Telerik team
answered on 31 Oct 2012, 01:01 PM
Hi MIchael,

This behaviour is observed when you add FirstOrDefault() to your query.
If you are using ToList() OpenAccess issues similar query to the one created by Entity Framework.

Changing the shape of the query enables us to load the Company instance by Id and push it to the cache for reuse later.
If you have any concerns about the change of the shape, please share them with us so we can discuss them and see if there are any possible work around.

Kind regards,
Viktor Zhivkov
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
General Discussions
Asked by
Top achievements
Rank 2
Answers by
Viktor Zhivkov
Telerik team
Share this question