Inheritance and HasContraint via Fluent API

2 posts, 0 answers
  1. Greg
    Greg avatar
    11 posts
    Member since:
    Aug 2014

    Posted 05 Aug 2014 Link to this post

    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.

  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 07 Aug 2014 Link to this post

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