Problem after save

Posts   
 
    
ThePhred
User
Posts: 3
Joined: 21-Feb-2006
# Posted on: 21-Feb-2006 23:17:13   

I am using LLBLGen Pro with CoreLabs MySqlDirect version 3.20.9.0 and .Net 1.1. The MySql Version is 4.0.24. I am using the SelfServicing Model. Using the 1.0.2005.1 Final Demo version of the LLBLGen Designer.

I am using a autoincriment primary key. When I create new entity and fill in some info (not including the primary key) and save it, after the save, all the properties of the entity that refer to columns in the database throw exceptions (System.InvalidCastException). It appears to me that once saved (and it saves correctly), the generated primary key is not loaded correctly and there is some sort of problem with that, maybe, that invalidats the other fields.

Basically, from what I gather, what should be happening, is that the autogenerated primary key is supposed to be fetched on save (and it is issueing the correct 'SELECT LAST_INSERT_ID()' to the database) and the object should continue to be usable. For me, however, the object just breaks. I was able to manually get the LAST_INSERT_ID and run a FetchUsingPK to get the object functional again, but this is a temp workaround.

Thankyou in advance for your help.

Michael

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Feb-2006 02:26:35   

What is the datatype of the primary key? Can you post some of the code for the entity creation and save?

Thank You.

ThePhred
User
Posts: 3
Joined: 21-Feb-2006
# Posted on: 22-Feb-2006 17:05:23   

SQL for the PK column:

site_id int(10) unsigned NOT NULL auto_increment

The C#.Net code I am using to do the save is spread out somewhat, but the LLBLGen related lines are here:


cm.AddNew(); // Using a currency manager to add the new row;

// Make changes to data through databindings

// Grab the current item (the new row).  I use EntityBase because this is in manager
// code that needs to work with Entities of different kinds SD.LLBLGen.Pro.ORMSupportClasses.EntityBase theEntity = (SD.LLBLGen.Pro.ORMSupportClasses.EntityBase)cm.Current; 

theEntity.Save();

Before the save, the theEntity object looks great, but after, all the properties refering to database columns throw exceptions when read.

Because the above code didn't work I tried a simple test to see if it would work in the simple case, but the results were the same.


SiteEntity se = new SiteEntity();
se.SiteName = "Test";
se.Save();

ThePhred
User
Posts: 3
Joined: 21-Feb-2006
# Posted on: 22-Feb-2006 18:11:28   

Ok, it looks like it is a problem with the fact that the PK is unsigned. Is this a quirk of the CoreLabs driver? Is there anywhere I should have looked for info that would say to use signed (not unsigned) for primary keys?

Overall though, the problems is solved. Thankyou for you time.

Michael

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Feb-2006 18:51:43   

ThePhred wrote:

Ok, it looks like it is a problem with the fact that the PK is unsigned. Is this a quirk of the CoreLabs driver? Is there anywhere I should have looked for info that would say to use signed (not unsigned) for primary keys?

Overall though, the problems is solved. Thankyou for you time.

Michael

Unsigned ints resolve to different types than signed ints, similar to unsigned shorts/bytes/longs etc. This is unfortunately a choice of the provider (corelab), as the datareader.GetValue() returns the value already in a .net type, so that's what llblgen pro obeys.

Frans Bouma | Lead developer LLBLGen Pro
steve7a
User
Posts: 3
Joined: 22-Jan-2007
# Posted on: 14-Feb-2007 14:57:47   

I've got precisely the same problem. I understand from your answer that the root of the problem lies with the behaviour of the CoreLabs driver. However, whatever the cause, the result is that the functionality of the Entity class is broken and so this should be considered as a bug. There is certainly nothing wrong with using an unsigned int as an auto-increment primary key.

I gathered that Michael fixed the problem by simply switching to a signed int. Unfortunately, I can't do this. So, taking into account this bug, if I want to read from the entity object after I have saved it, what would be the best way to do it?

Thanks for your help, Steve

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 15-Feb-2007 11:39:36   

steve7a wrote:

I've got precisely the same problem. I understand from your answer that the root of the problem lies with the behaviour of the CoreLabs driver. However, whatever the cause, the result is that the functionality of the Entity class is broken and so this should be considered as a bug. There is certainly nothing wrong with using an unsigned int as an auto-increment primary key.

I gathered that Michael fixed the problem by simply switching to a signed int. Unfortunately, I can't do this. So, taking into account this bug, if I want to read from the entity object after I have saved it, what would be the best way to do it?

If the provider uses .net type T for a given db type, we use that too.

This is an old thread, almost a year old. So before I go further, please provide: - your llblgen pro version - runtime lib version you're using (see: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7722) - corelab provider version

Because this thread is old, and your problem might be different, it's not that wise to post in old threads. Please next time start a new thread, explain YOUR situation and we can go from there. You can continue here in this thread, as the discussion has already been opened here.

Frans Bouma | Lead developer LLBLGen Pro