Hello,
I am using LLBLGen 3.5 (December 11th 2012) running against .net 4.0.
I have the following tables:
CREATE TABLE [dbo].[Baumart](
[id] [int] NOT NULL,
[gattung] [nvarchar](50) NOT NULL
CONSTRAINT [PK_Baumart] PRIMARY KEY CLUSTERED
(
[id] ASC
)
) ON [PRIMARY]
CREATE TABLE [dbo].[Baum](
[id] [uniqueidentifier] NOT NULL,
[x] [decimal](14, 6) NULL,
[y] [decimal](14, 6) NULL,
[projekt_id] [uniqueidentifier] NOT NULL,
[baumart_key] [int] NULL,
CONSTRAINT [PK__Baum] PRIMARY KEY CLUSTERED
(
[id] ASC
)
) ON [PRIMARY]
The two tables have a model-only relationship. Baumart.id <-> Baum.baumart_key with Baumart being on the primary key side.
I am creating a projection of the table Baum:
LinqMetaData metaData = new LinqMetaData(adapter);
var q = from baum in metaData.Baum
select new KurzBaumEntity
{
Id = baum.Id,
ProjektId = baum.ProjektId,
X = baum.X,
Y = baum.Y,
Baumart = baum.Baumart
};
Enumerating q leads to 2 SQL statements being executed:
1 fetching the Baum entities
2 fetching the Baumart entities
The second statement causes an exception:
Operand type clash: uniqueidentifier is incompatible with int
Here comes the second statement:
exec sp_executesql N'
SELECT
[LPA_L1].[gattung] AS [Gattung],
[LPA_L1].[id] AS [Id]
FROM [dbo].[Baumart] [LPA_L1] WHERE
(
(
(
(
EXISTS (SELECT [LPA_L2].[BaumartKey] FROM
(
SELECT [LPLA_1].[id] AS [Id],
[LPLA_1].[projekt_id] AS [ProjektId],
[LPLA_1].[x] AS [X],
[LPLA_1].[y] AS [Y]
1 AS [LPFA_2] FROM [dbo].[Baum] [LPLA_1]
) [LPA_L2] WHERE
(
(
(
(
(
(
(
([LPA_L2].[ProjektId] = @p1) AND
( [LPA_L2].[X] > @p2)) AND ( [LPA_L2].[X] < @p3)) AND ( [LPA_L2].[Y] > @p4)) AND ( [LPA_L2].[Y] < @p5)))) AND [LPA_L2].[Id] = [LPA_L2].[BaumartKey]))))))',
N'@p1 uniqueidentifier,@p2 decimal(14,6),@p3 decimal(14,6),@p4 decimal(14,6),@p5 decimal(14,6)',
@p1='CDB39687-6C7C-44A2-AE67-01582157B7A3',@p2=677734.965402,@p3=678225.326249,@p4=221193.440343,@p5=221443.559652
The error is caused by the statement:
AND [LPA_L2].[Id] = [LPA_L2].[BaumartKey]
This should actually be
AND [LPA_L1].[Id] = [LPA_L2].[BaumartKey]
Thank you for your help on this issue!
Best regards
Nasser Brake