I'm using dotconnect to work with a oracle 11g database and so far i created the db with code first and i´m using GUIDs as identifiers
At the moment the guids are created with the 'default value ' feature and the use of the SYS_GUID() function of oracle.
After insert of new data the guids look like this:
GUID reptresentation when i select it with linq to ef:
'55D3C5756E9342939F5CCE44AC87AEE2'
GUID representation in SQL-Developer
'75c5d355-936e-9342-9f5c-ce44ac87aee2'
So the string representations differ. I read some articles and found out that .net guids ("Guid") and oracle guids(RAW) have a different structure.
So my conclusion is that i always have to use the .net GUID type to generate new guids and cant use SYS_GUID() because the oracle guid would always have the "wrong" value in .NET . IS that right?
Or did i something wrong at the code first part? I used the Guid datatype and it is mapped to oracle type "RAW" .
Thanks.
GUID String Representation in SQL Developer and EF differ
-
- Posts: 16
- Joined: Mon 22 Jun 2015 08:38
Re: GUID String Representation in SQL Developer and EF differ
These are two representations of the same GUID:
The output would be:
String representation: 75c5d355-936e-9342-9f5c-ce44ac87aee2
Binary representation: 55 D3 C5 75 6E 93 42 93 9F 5C CE 44 AC 87 AE E2
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.
Code: Select all
Guid guid = new Guid("75c5d355-936e-9342-9f5c-ce44ac87aee2");
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();
String representation: 75c5d355-936e-9342-9f5c-ce44ac87aee2
Binary representation: 55 D3 C5 75 6E 93 42 93 9F 5C CE 44 AC 87 AE E2
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.
-
- Posts: 16
- Joined: Mon 22 Jun 2015 08:38
Re: GUID String Representation in SQL Developer and EF differ
Ok thanks.
Looks like i should always assign a new guid with Guid.NewGuid().ToByteArray(). instead of Guid.NewGuid()
Looks like i should always assign a new guid with Guid.NewGuid().ToByteArray(). instead of Guid.NewGuid()
-
- Posts: 16
- Joined: Mon 22 Jun 2015 08:38
Re: GUID String Representation in SQL Developer and EF differ
I still have problems with that guids in my web project:
The application gets the guid in this representation: '61AA7DD78C39614696358AD4E45366FA'
But in a linq where statement i need the Guid datatype so i convert it into a guid:
61aa7dd7-8c39-6146-9635-8ad4e45366fa
and the linq statement converts the where part to:
result: records with FK=61AA7DD78C39614696358AD4E45366FA are not found
So it is not possible to use dotConnect and entity framework with oracle guids ???
The application gets the guid in this representation: '61AA7DD78C39614696358AD4E45366FA'
But in a linq where statement i need the Guid datatype so i convert it into a guid:
So the guid representation is changed to:var guid = Guid.Parse(id);
61aa7dd7-8c39-6146-9635-8ad4e45366fa
and the linq statement converts the where part to:
Code: Select all
...WHERE "Extent1".FK = (CAST('61aa7dd7-8c39-6146-9635-8ad4e45366fa' AS RAW(16)))...
So it is not possible to use dotConnect and entity framework with oracle guids ???
Last edited by christian_bertram on Wed 07 Oct 2015 08:43, edited 1 time in total.
-
- Posts: 16
- Joined: Mon 22 Jun 2015 08:38
Re: GUID String Representation in SQL Developer and EF differ
Ok so i made some more research and find a half satisfying solution.
When i get back a guid string vom the client i always have to change the byte order of this guid to use it in a linq expression:
with the extension method i got from
http://stackoverflow.com/questions/8064 ... rsion?lq=1
Only that way the guid is parsed correctly inside the sql query created yb EF:
(CAST(:p__linq__0 AS RAW(16))
can somebody confirm this or give me an other solution?
i also cant understand why in other hand this gives the correct results:
It looks like the wrong parsing during a select (oracledb-->entity) is the actual problem but i cant
control that or can i ?
thanks.
When i get back a guid string vom the client i always have to change the byte order of this guid to use it in a linq expression:
Code: Select all
var guid = Guid.Parse(id).FlipEndian();
http://stackoverflow.com/questions/8064 ... rsion?lq=1
Only that way the guid is parsed correctly inside the sql query created yb EF:
(CAST(:p__linq__0 AS RAW(16))
can somebody confirm this or give me an other solution?
i also cant understand why in other hand this gives the correct results:
Code: Select all
var newID = Guid.NewGuid();
newSubItem = new A();
newSubItem.ID = newID;
... save changes ...
var newQuery = from i in context.A where i.ID == newID select i;
control that or can i ?
thanks.
Re: GUID String Representation in SQL Developer and EF differ
Please send us a small test project with the corresponding DDL/DML script so that we can reproduce the problem in our environment.