PK GUID Save() Bug II

Posts   
 
    
Diego
User
Posts: 15
Joined: 06-Jul-2005
# Posted on: 06-Dec-2005 21:28:15   

Hello. I was having an error with a GUID in a PK, and although I fixed it, I think that it is important to tell my history.

I'm using the lastest build of the LLBL (Release date: 03-dec-2005. Version: 1.0.2005.1) and I'm working with SQLServer 2005 Express.

Here is my code:


                BookingPaxEntity pax = new BookingPaxEntity();
                pax.Guid = Guid.NewGuid();
                pax.BookingId = 1;
                pax.FirstName = "Name1";
                pax.FirstSurname = "Surname1";
                pax.IsMale = true;
                adapter.SaveEntity(pax);

"Guid" is the PK of my pax entity. However, when the adapter.SaveEntity line is executed I get this error:

"An exception was caught during the execution of an action query: Operand type clash: numeric is incompatible with uniqueidentifier. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."

When I checked the Query Executed I found this:


INSERT INTO [Bookings].[dbo].[BookingPax] ([BookingId], [FirstName], [FirstSurname], [IsMale]) 
VALUES (@BookingId, @FirstName, @FirstSurname, @IsMale);
SELECT @Guid=SCOPE_IDENTITY()
    Parameter: @Guid : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Output. Value: <undefined value>.
    Parameter: @BookingId : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.
    Parameter: @FirstName : String. Length: 75. Precision: 0. Scale: 0. Direction: Input. Value: Name1.
    Parameter: @FirstSurname : String. Length: 75. Precision: 0. Scale: 0. Direction: Input. Value: Surname1.
    Parameter: @IsMale : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True.

I'm not an expert in SQL (that's why I use LLBL stuck_out_tongue_winking_eye ) however the <undefined value> in the Guid seemed a bit strange for me.

I checked the designer and I found this:

Field Name | .NET Type | Target | DB Type | IsPK | IsIdentity | Sequence name

Guid | System.Guid | Guid | uniqueidentifier | true | true | SCOPE_IDENTITY

So I realized that the problem were the "IsIdentity" and the "Sequence Name" attributes of the field.

The IsIdentity was setting to true, because I used to have an autogenerated int as my PK. And when I modified it in the DB and refreshed the catalog, the IsIdentity property of that field remained unchanged.

To fix this I removed the entity from the project and then I added it again. And I got this:

Field Name | .NET Type | Target | DB Type | IsPK | IsIdentity | Sequence name

Guid | System.Guid | Guid | uniqueidentifier | true | false |

and everything worked fine!

And that was all, however still think that the designer should detect the change of the Identity property of one field wink .

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 06-Dec-2005 22:13:24   

Erm, your Guid field isn't a guid, but an identity field. Do you have mixed up dbspecific and dbgeneric projects?

Frans Bouma | Lead developer LLBLGen Pro
Diego
User
Posts: 15
Joined: 06-Jul-2005
# Posted on: 07-Dec-2005 13:56:42   

This is what happened:

The PK of my Pax entity was a Field named "Id". The dbtype of this field was "int" and it was an identity field. I had generated the entities and everything was working fine untill I realized that "Guid" would be a better type for my Field "Id" instead of "int".

So a changed the dbtype of the Field "Id" to "uniqueidentifier" (In fact I had to remove the "Id" field of type "int" and then I had to add a new field "Id" of type "uniqueidentifier"). So, my "Id" field became a non Identity field.

I refreshed the catalog (the Designer informed me that the type of the Id field in the Pax entity had changed) and when I entered to the properties of the entity Pax in the designer I found this weird thing:

Field Name | .NET Type | Target | DB Type | IsPK | IsIdentity | Sequence name

Id | System.Guid | Guid | uniqueidentifier | true | true | SCOPE_IDENTITY

To fix it I removed the entity from the project, refreshed the catalog, and then added the entity again (Of course I don't realized this was wrong until I saw the exceptions with the generated code).

Sorry for my English (It's a bit difficult to me to write in past tense) and my unclear previous post flushed . I think I made a mess because when things weren't working I renamed the Pax PK field from "Id" to "Guid".

Now everything is working well, and actually I realize that what happened to me is a very uncommon situation.

I hope this post helps!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Jun-2006 08:05:12   

This bug was fixed on 30 January 2006, please use the latest version of LLBLGen Pro