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

MetadataException "Failed to create ref and poly ref fields of class"

4 Answers 120 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Roger
Top achievements
Rank 1
Roger asked on 14 Dec 2010, 03:22 PM
I have a domain model that I access using the DataManager (generated by DSW) and I have several working entities.  One entity that I've recently added throws an exception on the following call:

var context = new DataManager(new MyDataModel());
var myEntities = context.ReadEntities<MyEntity>().Where(e => !e.IsDeleted);

I'm using a similar pattern for other entities, so I'm sure it's not that, and I have updated the related tables from the database, but still get a MetadataException with the message "Failed to create ref and poly ref fields of class".  I can't find a reference to this message anywhere.  What does it mean and how can I fix it?

4 Answers, 1 is accepted

Sort by
0
Roger
Top achievements
Rank 1
answered on 14 Dec 2010, 05:33 PM
Digging deeper, I see the following in the inner exception:
InnerException: System.ArgumentException
     Message=Cannot create converter for SQL type: 'uniqueidentifier' CLR type: ''.

I have identified the error as being a relationship where the foreign key is a GUID, but the GUID is not the primary key in the source entity.  When I use the Mapping Details Editor, the only choices I have for the source are the primary key and "<None>".

Is it not possible to use a non-primary key value as a foreign key?  This seems to me to be a fairly basic requirement.
0
Alexander
Telerik team
answered on 16 Dec 2010, 10:29 AM
Hi Roger,

Normally to define a relation you need a foreign key column in the referencing table (to keep the identity of the referenced record) and a primary key (or unique) column in the referenced table. That is why in the Details Editor you see only the primary key columns for the Target End. Nevertheless, you should be able to select any column as foreign key column at the Owner End. Having a relation based not on a primary key column but on a unique column is not currently supported. Could this be your case?

Best wishes,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
0
Roger
Top achievements
Rank 1
answered on 16 Dec 2010, 06:36 PM
Yes, my relationship is on a unique key, not a primary key.  Not being able to join on a unique key means that I am going to have to add a lot of join tables, which is frustrating and disappointing.
0
Dimitar Kapitanov
Telerik team
answered on 17 Dec 2010, 08:48 AM
Hi Roger,
We believe it is really justified to be able to make joins based not only on foreign key columns but also on unique columns. We added a feature request in our backlog, and will schedule it for development as soon as possible. I think we will be able to bring that in Q1 if not earlier.

Regards,
Dimitar Kapitanov
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
Development (API, general questions)
Asked by
Roger
Top achievements
Rank 1
Answers by
Roger
Top achievements
Rank 1
Alexander
Telerik team
Dimitar Kapitanov
Telerik team
Share this question
or