This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Heya, I've set up a MySQL database and wish to use a GUID for a primary key. As MySQL doesn't support Guids, we've got it using a varchar(36). When I try to do retrieve an entity from this table, like so: MySQL: CREATE TABLE testtable (id VARCHAR(36) NOT NULL, PRIMARY KEY(id)); INSERT INTO testtable VALUES ("6cab5130-69a5-11dd-ad8b-0800200c9a66"); Code behind: public class TestTable : Entity<Guid>{} ... _lightSpeedContext = new LightSpeedContext<UnitOfWork> using(var unitOfWork = _lightSpeedContext.CreateUnitOfWork()) This is throwing an exception: "Unable to materialize field [Id] on type [TestGuid.TestTable]", with an inner exception of "{"Specified cast is not valid."}". Is it possible for Lightspeed to translate from MySQL's varchar(36) to a Guid, if the entities type of primary key is a Guid? Cheers Beaker |
|
|
I am having the exact same problem ... I am also using MySQL and would really like to use Guid's for my identity method. Any help with this would be greatly appreciated. |
|
|
Would you guys prefer to store Guids as varchar or binary? Binary is smaller and faster but varchar is more readable. Cheers, Andrew.
|
|
|
I don't mind how they are stored internally either would be fine. Thanx |
|
|
If I can add my two cents worth. Whenever I have used GUIDs for "object" ids we never cared for the textual representation of it, it was always used in a programmatic context - never for human consumption, so whatever produces faster and cleaner code would be our preference. |
|
|
Hi All, Guids are now supported in all LS back ends. For databases that don't have a native Guid type, VARCHAR should be used. Available in the latest nightly. Cheers, Andrew. |
|
|
Thanx heaps for the fast support =) |
|
|
Mad props guys, works like a charm. You are teh pwnz, and Lightspeed turn around (zaaa!) Cheers |
|
|
Thanx again for this fix I am using MySQL and it works well, except I have one small problem. I have set my lightspeed object's Identity Method property to "Guid" and the Identity Type property to "String" using the lightspeed object model editor in VS2008, however when I use the editor to create my database tables, it creates the Id column as a VARCHAR(10) instead of the required VARCHAR(36) thus I have to then manually go and update all my tables. Is there something I am doing wrong? |
|
|
Yes and no. The identity type should be set to Guid, not string -- at the entity level, you don't have to care about the fact that it is implemented in the MySQL table as a varchar(36) rather than a specialised type like in SQL Server. LightSpeed will take care of that for you. However, once you fix this, you'll find that the designer no longer knows how to do schema round-tripping on the identity column at all -- we haven't taught the designer how to handle the GUID to string translation yet. (The designer tends to lag a few days behind core features.) So now you won't be able to use the designer to create tables with GUID identities at all! I'll have a look at the designer support now and see if we can get it into tonight's nightly build. |
|
|
Oh ... Thanx, That makes sense because I did try setting the Identity Type as Guid first and then as you mentioned, I was unable to generate the tables at all. Thanx again for the fast response. |
|
|
This will be in nightly builds numbered 20080822 and above, available from about 1800 GMT. Update Database, when creating a new table with for an entity with identity type Guid, will now create a Id column of type CHAR(36) (or VARCHAR(36), depending on the database) if the database does not support a native GUID type. Please let me know if you run into any problems. |
|