GUIDs not matching

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
mstrawmyer
Posts: 2
Joined: Mon 15 Dec 2008 04:56

GUIDs not matching

Post by mstrawmyer » Sat 21 Feb 2009 20:23

I have an Oracle database table with a column that is RAW(16). The table has several rows with a value of '72994588004644B594CB271D699EE67B' in this colum. I run a query like this in my code where tenantId parameter is set to the value above and no results are returned.

var results = context.AppSetting.Where(a => a.TenantId == tenantId)

When I use Visual Studio to peek at AppSetting, it has all the rows with GUIDS of value '884599724600B54494CB271D699EE67B'. I have no idea how it is getting this value out of what is stored in the database. Since it is different it isn't querying any of the rows from my table. I don't understand why the value is getting pulled out differently or what to do in order to make my query return results. Please advise.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 25 Feb 2009 15:06

I advise you to compare not the strings, but either byte arrays or guids.
For comparing guids you should execute OracleDataReader.GetGuid() with the column number as parameter.
For comparing byte arrays you should call tenantId.ToByteArray() and then read a byte array from the database using OracleDataReader.
If you wish to see the guid generated from the binary string like '72994588004644B594CB271D699EE67B', you should use the code like following:

Code: Select all

public static Guid BinaryStringToGuid (string binaryString) {
      byte[] res = new byte[16];
      for (int i = 0; i < 16; i++) {
        res[i] = (byte)int.Parse(binaryString.Substring(2*i, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
      }
      return new Guid(res);
    }

Post Reply