Ok. The SQL is quite what is needed. But I'm confused why there are more queries that are executed? 1 query for every content that is returned. And the resulted collection is not what is needed. Bellow is the dump...
[404] Generated Sql query:
[404] Query: SELECT DISTINCT [PlasmaBoxCore].[dbo].[Content].[ID] AS [Id], [PlasmaBoxCore].[dbo].[Content].[ContentName], [PlasmaBoxCore].[dbo].[Content].[Path], [PlasmaBoxCore].[dbo].[Content].[Duration], [PlasmaBoxCore].[dbo].[Content].[Type], [PlasmaBoxCore].[dbo].[Content].[ContentType], [PlasmaBoxCore].[dbo].[Content].[Title], [PlasmaBoxCore].[dbo].[Content].[MediaType], [PlasmaBoxCore].[dbo].[Content].[HouseID] AS [HouseId] FROM ( [PlasmaBoxCore].[dbo].[Content] LEFT JOIN [PlasmaBoxCore].[dbo].[FieldValues] ON [PlasmaBoxCore].[dbo].[Content].[ID]=[PlasmaBoxCore].[dbo].[FieldValues].[ContentID])
[404]
[404] Generated Sql query:
[404] Query: SELECT [PlasmaBoxCore].[dbo].[FieldValues].[ID] AS [Id], [PlasmaBoxCore].[dbo].[FieldValues].[ContentID] AS [ContentId], [PlasmaBoxCore].[dbo].[FieldValues].[FieldDescriptionID] AS [FieldDescriptionId], [PlasmaBoxCore].[dbo].[FieldValues].[FieldValue] FROM [PlasmaBoxCore].[dbo].[FieldValues] WHERE ( ( [PlasmaBoxCore].[dbo].[FieldValues].[ContentID] = @ContentId1))
[404] Parameter: @ContentId1 : Int32. Length: 1. Precision: 10. Scale: 0. Direction: Input. Value: 1.
[404]
[404] Generated Sql query:
[404] Query: SELECT [PlasmaBoxCore].[dbo].[FieldValues].[ID] AS [Id], [PlasmaBoxCore].[dbo].[FieldValues].[ContentID] AS [ContentId], [PlasmaBoxCore].[dbo].[FieldValues].[FieldDescriptionID] AS [FieldDescriptionId], [PlasmaBoxCore].[dbo].[FieldValues].[FieldValue] FROM [PlasmaBoxCore].[dbo].[FieldValues] WHERE ( ( [PlasmaBoxCore].[dbo].[FieldValues].[ContentID] = @ContentId1))
[404] Parameter: @ContentId1 : Int32. Length: 1. Precision: 10. Scale: 0. Direction: Input. Value: 2.
.
.
.
and so on...
.
.
.
And one other question: How to add another restriction to the join part
select c.*
from Content c
left outer join FieldValues f
on f.ContentID=c.ID
and f.FieldDescriptionID=1
order by f.FieldValue;
if I add a predicate it adds it to query with "where" clause
select c.*
from Content c
left outer join FieldValues f
on f.ContentID=c.ID
where f.FieldDescriptionID=1
order by f.FieldValue;
which causes wrong result set.
Regards