Guid: bytes order

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Oleg Mikhaylov
Posts: 5
Joined: Mon 28 Jan 2013 14:06

Guid: bytes order

Post by Oleg Mikhaylov » Wed 27 Feb 2013 16:17

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.

Shalex
Devart Team
Posts: 8088
Joined: Thu 14 Aug 2008 12:44

Re: Guid: bytes order

Post by Shalex » Wed 27 Feb 2013 17:37

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.

silvaio
Posts: 1
Joined: Fri 22 Nov 2013 08:45

Re: Guid: bytes order

Post by silvaio » Fri 22 Nov 2013 12:53

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

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Guid: bytes order

Post by MariiaI » Fri 22 Nov 2013 15:33

Silvain, we have answered you by e-mail.

Post Reply