Open firedog opened 3 years ago
What is the SQL that is produced? I.e. is it a mapping or SQL gen issue?
Seems like an SQL issue as the "complex" columns aren't selected...
SELECT [C].[Id] as [Id], [C].[Make] as [Make], [C1].[Id] as [Chassis__Id], [C1].[Wheels] as [Chassis__Wheels], [C1].[CarId] as [Chassis__CarId], [E].[Id] as [Engine__Id], [E].[Cylinders] as [Engine__Cylinders] FROM [Cars] [C]
INNER JOIN [Chassis] [C1] ON [C].[Id] = [C1].[CarId]
INNER JOIN [Engines] [E] ON [C].[EngineId] = [E].[Id]
WHERE ([C].[Id] = @0)
Compared with the SQL that is generated from the second statement (selecting the Engine) we can see that the Identity object is correctly selected there.
SELECT [E].[Id] as [Id], [E].[Cylinders] as [Cylinders], [E].[Identity__Serial] as [Identity__Serial], [E].[Identity__Manufacturer] as [Identity__Manufacturer]
FROM [Engines] [E]
WHERE ([E].[Id] = @0)
When querying using NPoco.Linq Include() to pull in referenced data NPoco seems to ignore properties in the referenced objects that are mapped using Complex mapping. The type of reference, OneToOne or Foreign, does not seem to matter.
Tested on SQL Server 2019 using .NET Core 5.0 and Npoco version 5.3.1.
To reproduce create a .NET Core Console application and replace Program.cs with the following code:
Create a SQL Server database and run the following sql script to create the tables
The output when running this application is: