Vincent
Vincent

Reputation: 1557

getting Guid from database

Something strange happend, I am no longer able to get the GUID type from my mysql database with the .net entity model.

A while ago i created a database which used Guid's as ID. I created a connection to this database with the entity framework and everything worked fine.

however i lost the database a while ago and i had to create it again, now however, the classes that get created by the entity framework model have a string as ID, not the GUID it used to be.

What type do i need to make my ID's in my mysql database so I can simply do the following:

Image.ID = Guid.NewGuid();
EntityModel.Image.Add(Image);
EntityModel.SaveChanges();

This used to work fine, now I (obviously) get an error: "Cannot implicitly convert type 'System.Guid' to 'string'"

I cannot remember how I once did it and am wondering if people here could help. I did read about UUID() but that's not how I did it. Somehow I've got the feeling mysql updated and somehow it's no longer possible but that seems odd to me.

I did look into this and saw a lot of people suggesting making the id's a binary type in mysql and converting the Guid to it's binary form and storing that. I'm hoping not to write a conversion class to implicitly cast Guid to Binary...

Upvotes: 0

Views: 732

Answers (1)

Robert McKee
Robert McKee

Reputation: 21477

Binary(16) should work with the newer connectors if you use 'Old Guids=true', otherwise it wants to use char(36)

Upvotes: 2

Related Questions