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 ) 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 .