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

Inheritance and HasContraint via Fluent API

1 Answer 65 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Greg
Top achievements
Rank 1
Greg asked on 05 Aug 2014, 07:34 AM
Hello,

I'm fairly new to using Telerik Data Access and I tried searching for this exact issue in the forum but didn't find it. I am trying to set up a 1:1 relationship on an entity that is using vertical inheritance, however, when I try to add the constraint I get the following error:

The property Id is not mapped to a column. (Id is my primary key.)

Parent class mapping
parentConfig.MapType()
    .ToTable("Parent");

parentConfig.HasProperty(t => t.Id)
   .IsIdentity(KeyGenerator.Guid);

Inherited/child mapping
childConfig.MapType()
  .Inheritance(InheritanceStrategy.Vertical)
  .ToTable("Child");

childConfig.HasAssociation(t => t.ChildAssociation)
   .HasConstraint((c, l) => c.Id == l.Id) --This is causing the issue
   .AsOneToOne()
   .IsRequired();

childConfig.HasDiscriminatorValue("1");

Association mapping
associationConfig.MapType()
    .ToTable("ChildAssociation");

associationConfig.HasProperty(t => t.Id)
   .IsIdentity(KeyGenerator.Guid);

It seems that since the Id property is mapped on the parent type, the HasConstraint method doesn't recognize it on the derived type. I did manage to get a 1:1 relationship setup on two classes that have no inheritance mapping. Is there a workaround for this or is there something I am missing? Thanks.

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 07 Aug 2014, 09:15 AM
Hi Greg,

I am afraid that the behavior you are experiencing is a known issue on our side and unfortunately there isn't any workaround for this problem. I could only recommend you to change the design of your model. 

Please excuse us for the inconvenience caused.

Do not hesitate to contact us if you have any more questions or need any further assistance. 

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Getting Started
Asked by
Greg
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or