Operand type clash: uniqueidentifier is incompatible with int

Posts   
 
    
nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 19-Feb-2013 12:43:47   

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

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 19-Feb-2013 16:17:21   

What's KurtzBaumEntity? An entity type with inheritance in the model? or a poco class?

Frans Bouma | Lead developer LLBLGen Pro
nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 19-Feb-2013 16:23:06   

KurzBaumEntity is a poco class and not part of the model.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Feb-2013 18:54:37   

Are you sure you have posted the correct query?

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]

The above should have failed, as the inner select doesn't provide a field with an alias "BaumartKey".

nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 19-Feb-2013 19:18:35   

My Bad! the original query had many more columns and while trying to reduce it I must have msised baumart_key. I am attaching the original query.

Attachments
Filename File size Added on Approval
QueryEmitedFromProjection.sql 2,016 19-Feb-2013 19:18.47 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Feb-2013 19:30:41   

Would you please rovide the LinqSupportClasses dll version number (build no.)? hint: Right click the file and get the file version.

nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 20-Feb-2013 09:08:39   

LinqSupportClasses version is 3.5.12.1211.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Feb-2013 23:15:50   

I couldn't reproduce it. Using the attached llblgen project on northwind, and using the following code:

using (var adapter = new DataAccessAdapter())
{
    LinqMetaData metaData = new LinqMetaData(adapter);

    var q = from baum in metaData.Test3
            select new 
            {
                Id = baum.Id,
                ProjektId = baum.ParentId,
                X = baum.Name,
                Parent = baum.Test2
            };

    q.ToList();
}
Attachments
Filename File size Added on Approval
Northwind.llblgenproj 70,898 20-Feb-2013 23:16.22 Approved
nbrake
User
Posts: 30
Joined: 18-May-2008
# Posted on: 21-Feb-2013 17:36:47   

Hello,

I tried to open the model file in LLBLGen and it fails with the following message

Message type: Error Message text: The mapping of sub-element 'ParentId' of entity 'Test3' for the target database with the driver 'SQL Server 2000/2005/2008/2008R2/2012/Express Driver (SqlClient)' has the following errors: - MappedTarget: The IsNullable flag on target field 'dbo.Test3.ParentId' is set to 'False' while the IsOptional flag of the mapped field 'ParentId (FK)' is set to 'True' Source: Test3 mapping Created on: Thursday, February 21, 2013 5:26 PM Corrections/suggestions Choice 1: Open containing element 'Test3' in its editor and manually correct the errors.

I am using LLBLGen 3.5 (December 11th, 2012)

Best regards

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Feb-2013 18:20:24   

I guess the project wasn't saved before attacheing it. Please check try the attached one.

Attachments
Filename File size Added on Approval
Northwind.llblgenproj 71,962 21-Feb-2013 18:20.50 Approved