Guid in Storage, but String in Conceptual

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Alladin
Posts: 149
Joined: Mon 27 Nov 2006 16:18
Contact:

Guid in Storage, but String in Conceptual

Post by Alladin » Wed 06 Jul 2011 16:41

Hello there,

We use Guids (RAW(16)) as primary keys for our tables, so far so good. EF4 also supports Guids properly.

However we are not satisfied with System.Guid type being a struct. Our classes have many relations which are optional, so this is effective waste of memory even if field is Nullable. We have many dictionaries which use Guid as a key, those dictionaries occupy lot of memory holding basically a copy of all Guids used as primary keys. If some wise guy from MS would make Guid a reference type, this would save a lots of memory and processing power.

Now add in this play WCF Data Services, where you cannot modify your EF-generated classes (because of hard-coded metadata publishing mechanism). So these Guids basically coming down to the Silverlight client, causing there the same memory and performance problems.

So my idea was to replace all Guids with String types in conceptual model, but to leave Guids in Storage model. Unfortunately, EF Designer complaints that this mapping is not possible.

Is it possible to make such a mapping possible?

I've done some tests: if EF doesn't really know that column is RAW(16), instead of VARCHAR2(32), saving and querying work fine. Trick is to write base64 encoded version of the guid in string field.

However, Guids loaded as string back look like 8 chinese symbols - no base64 decoding is taking place.

Any ideas how to get rid of Guids in conceptual model, but preserve them in DB?

Thank you in advance,
Alladin

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

Post by AndreyR » Thu 07 Jul 2011 14:17

We are investigating the possibility to add the requested functionality.
I will let you know as soon as any new information is available.

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

Post by AndreyR » Wed 20 Jul 2011 14:52

The new "raw guid as string" SSDL type will be added in the nearest build (this build will be released in a week or so).
This type is partially supported: Insert, Update, and Delete operations are supported. The Select queries with Where conditions containing this type like the

Code: Select all

context.RawTable.Where(rawTable => rawTable.RawColumn == "D3BC058453DC43CCB7C542D8345388FD")
or

Code: Select all

string value = "D3BC058453DC43CCB7C542D8345388FD";
context.RawTable.Where(rawTable => rawTable.RawColumn == value)
are supported as well.

However, we cannot guarantee the correct handling of the LINQ Extension methods like

Code: Select all

context.RawTable.Where(rawTable => rawTable.RawColumn.Contains("DC43CCB7C542"))
or

Code: Select all

context.RawTable.Where(rawTable => rawTable.RawColumn.IndexOf("DC43CCB7C542") > 0)
This functionality is almost implemented, however, we have some questions regarding implementation details:

1. Is the default ('N') format "00000000000000000000000000000000" appropriate? Guid.ToString() uses the "00000000-0000-0000-0000-000000000000" ('D') format as the default one, but it is longer for 4 symbols.
2. Do you need the possibility to select the string representation format (i.e. select which of the 'N', 'D', 'B', 'P', 'X' formats to use for the string representation)?
3. What should be the empty string literal representation? Namely, in the query like

Code: Select all

context.RawTable.Where(raw => raw.RawColumn == "")
the "" literal should be translated to null or to Guid.Empty("00000000-0000-0000-0000-000000000000")?
If you have any other propositions, please let us know.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 29 Jul 2011 09:21

New build of dotConnect for Oracle 6.30.196 is available for download!
It can be downloaded from http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with valid subscription only): http://secure.devart.com/ .

For more information, please refer to http://www.devart.com/forums/viewtopic.php?t=21605 .

Post Reply