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

5 posts, 0 answers
  1. Roger
    Roger avatar
    32 posts
    Member since:
    Feb 2009

    Posted 14 Dec 2010 Link to this post

    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?
  2. Roger
    Roger avatar
    32 posts
    Member since:
    Feb 2009

    Posted 14 Dec 2010 Link to this post

    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.
  3. DevCraft banner
  4. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 16 Dec 2010 Link to this post

    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.
  5. Roger
    Roger avatar
    32 posts
    Member since:
    Feb 2009

    Posted 16 Dec 2010 Link to this post

    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.
  6. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 17 Dec 2010 Link to this post

    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.
Back to Top
DevCraft banner