This is a migrated thread and some comments may be shown as answers.

GUID problems

2 Answers 83 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Spencer LaDow
Top achievements
Rank 1
Spencer LaDow asked on 19 Aug 2010, 01:07 AM
Hello,

I have been trying to get a new project up and running using the new model designer but I keep running into an issue with GUIDs.  I have tried to made this as simple as I can to try to isolate the problem.  First I create a table named testtest on MySQL on my online server with one field in it that is a varchar(40). Next I create a simple winforms app and add a model connecting to my database and import the one table.  After the project reloads I proceed to the model explorer, select the ID field and change the type to Guid, and then select the table and change the Identity Mechanism to Guid.  In the form I have the following code.  I didn't assign anything to the query since it didn't matter.

private TestDatabaseDiagrams context = new TestDatabaseDiagrams();
        public Form1()
        {
            InitializeComponent();

            Testtest test = new Testtest();
            context.Add(test);
            context.SaveChanges();

            var qry = from c in context.Testtests select c;
            qry.ToList();
        }

The add works perfectly fine and the Guid is created but every time no matter what I do I get the following error at the qry.ToList():

OpenAccessException: Specified cast is not valid.

Stack Trace:at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)\r\n   at Telerik.OpenAccess.RT.ExceptionWrapper.Throw()\r\n   at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x)\r\n   at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.getObjectById(Object oid, Boolean validate)\r\n   at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.getObjectById(Object o, Boolean b)\r\n   at OpenAccessRuntime.DataObjects.QueryResultBase.resolveRow(Object row, OpenAccessPMProxy pm)\r\n   at OpenAccessRuntime.DataObjects.ForwardQueryResult.getNextData(Int32 windowIndex)\r\n   at OpenAccessRuntime.DataObjects.ForwardQueryResult.internalGet(Int32 requestedIndex)\r\n   at OpenAccessRuntime.DataObjects.ForwardQueryResult.get_Item(Int32 indexParam)\r\n   at Telerik.OpenAccess.RT.ListEnumerator.setCurrent(Int32 _pos)\r\n   at Telerik.OpenAccess.RT.ListEnumerator.Move(Int32 relative)\r\n   at Telerik.OpenAccess.RT.ListEnumerator.MoveNext()\r\n   at Telerik.OpenAccess.Query.TypedEnumerator`1.System.Collections.IEnumerator.MoveNext()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n  ... continues on with the application trace...

In the modeler if I have the Type set to String and I handle the creation myself everything works fine.  But I didn't want to have to deal with the Guids myself.

Thanks,

Spencer

2 Answers, 1 is accepted

Sort by
0
Spencer LaDow
Top achievements
Rank 1
answered on 19 Aug 2010, 01:45 AM
I forgot to mention I am using version 2010.2.714.1.
0
Serge
Telerik team
answered on 24 Aug 2010, 10:52 AM
Hi Spencer LaDow,

This seems like a bug in the configuration on our side, however there is a workaround that you can use. Let me explain a bit first. When reverse mapping we are creating two models - conceptual one (that you can edit from the designer) and a relational model that represents the database schema. The issue here is that we have a column object in the relational model and it has two properties that hold the open access type and the sql type (respectively the ado-type and sql-type properties).

What we need to do for OpenAccess to handle guids is to set the ado-type to guid and leave the sql-type to be varchar. You can modify this trough the model schema explorer, right click on the table and select Edit column. This will open up the table editor and there you will be able to specify the correct mapping. This will make your case to work, however it will modify both the ado-type and the sql-type which in turn will cause trouble if you at some point use the Update database wizard. It would pick the change in the sql type and generate script to modify the column. This can cause tremendous trouble.

The better solution is to modify the rlinq directly using the XML editor. Just right click on the rlinq and choose Open With... and select the Xml Editor. In it you will find the deserialized representation of our domain model. You will have to find the orm:schema node and in it the orm:table node that you want. There should be a collection of orm:column nodes that have the ado-type attribute. Replace its value with GUID. There is something else you have to do however. This column node might be in other places in the document. I suggest searching by the name of the column for others instances and modifying them as well.

We have added this to our internal tracker and will fix it for the next release. These are the only workarounds at the moment but they should be enough to get you started.

I hope this helps.

Greetings,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Databases and Data Types
Asked by
Spencer LaDow
Top achievements
Rank 1
Answers by
Spencer LaDow
Top achievements
Rank 1
Serge
Telerik team
Share this question
or