Page 1 of 1

Guid: bytes order

Posted: Wed 27 Feb 2013 16:17
by Oleg Mikhaylov
I'm migrating my database to MySQL and trying use BINARY(16) as replacement for Guid. It is good that dotConnect provides this option but how can I control bytes order?

E.g. there is following predefined guid in my script: X'2F8EF891EB5E454497D69D48F8756064', but when application retrieves it, it receives {91f88e2f-5eeb-4445-97d6-9d48f8756064}.

Is there some workaround? Thanks in advance.

Re: Guid: bytes order

Posted: Wed 27 Feb 2013 17:37
by Shalex
Oleg Mikhaylov wrote:I'm migrating my database to MySQL and trying use BINARY(16) as replacement for Guid. It is good that dotConnect provides this option but how can I control bytes order?
Do you mean the Binary As Guid connection string parameter?
Oleg Mikhaylov wrote:E.g. there is following predefined guid in my script: X'2F8EF891EB5E454497D69D48F8756064', but when application retrieves it, it receives {91f88e2f-5eeb-4445-97d6-9d48f8756064}.
These are two representations of the same GUID:

Code: Select all

    Guid guid = new Guid("91f88e2f-5eeb-4445-97d6-9d48f8756064");
    string stringGuid = guid.ToString();
    string binaryGuid = null;
    Byte[] bytes = guid.ToByteArray();
    foreach (var byt in bytes)
        binaryGuid += String.Format("{0:X2} ", byt);
    Console.WriteLine("String representation: " + stringGuid);
    Console.WriteLine("Binary representation: " + binaryGuid);
    Console.ReadKey();
The output would be:
String representation: 91f88e2f-5eeb-4445-97d6-9d48f8756064
Binary representation: 2F 8E F8 91 EB 5E 45 44 97 D6 9D 48 F8 75 60 64

If this doesn't help, please send us a small test project with the corresponding DDL/DML script to reproduce the issue in our environment.

Re: Guid: bytes order

Posted: Fri 22 Nov 2013 12:53
by silvaio
Hi there,

did this issue got resolved? I am using the dotConnect for MySql 8.1.26.0 with LinqConnect and seem to experience the same issue as Oleg.

In short the problem is that if Iā€™m trying to retrieve the record giving based on its binary(16) key value the result returns null. In my db a record is stored as the binary form of the value 'b8e0781e-3110-4283-a4ee-ef0e04633ec7'. From code I try to get this record as follows:

Guid id = new Guid(ā€œb8e0781e-3110-4283-a4ee-ef0e04633ec7ā€);
result = db.Instruments.SingleOrDefault(p => p.Id == id); //returns null, key does not exist

However, if I reverse the order of the first three blocks as in the following example, it seems to be working fine.
Guid id = new Guid(ā€œ1e78e0b8-1031-8342-a4ee-ef0e04633ec7");
result = db.Instruments.SingleOrDefault(p => p.Id == id); //returns the record

Does this have to do with .NET GUID to MySql UUID translation? If so,wouldn't it make sense to expect LinqConnect to manage this automagically?

Much appreciated, Silvain

Re: Guid: bytes order

Posted: Fri 22 Nov 2013 15:33
by MariiaI
Silvain, we have answered you by e-mail.