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.
GUIDs not matching
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:
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);
}