Vertical Inheritance - Extraneous Id Column

5 posts, 0 answers
  1. Chris
    Chris avatar
    3 posts
    Member since:
    Nov 2012

    Posted 07 Jul 2013 Link to this post

    Hi,

    I've got a very simple model which I'm trying to design.  As part of it, I want to have a PostalLocation base entity which contains the fields:

    Id

    Name

    Address1

    Address2

    Address3

    County

    Postcode

    Country

    Now, I want to have any other models which include postal data to inherit from this class.  For example, a CustomerSite entity.

    This seems pretty straightforward, following this guide.  I've created the CustomerSite entity and removed its automatically-generated Id column.  Then I've added the inheritance via the toolbox and set the inheritance strategy to Vertical.

    So far, so good.  No warnings in Visual Studio's list.  So, I go ahead and choose to update the database from the model.  I start with an empty database and run the script which OpenAccess generates.

    That's where the problem starts.  Now, VS reports this warning:

    Warning 1   The column with name 'Id' is not mapped to a property.  C:\Users\Chris\Documents\Visual Studio 2012\Projects\OATest\OATest.DAL\EntitiesModel.rlinq    0   0  

    It seems that the script has generated an Id column in the database for my derived entity, which according to the docs I shouldn't have.

    Unfortunately, this error prevents me from creating the service via the Add OpenAccess Service menu option (the entities aren't checkable in the list in the wizard).

    If I double-click the warning in VS's list and let the error be automatically fixed (by adding the Id property to the derived entity), I then get errors stating that there should not be identity members on a vertically inherited class.

    What am I doing wrong here?!

    (I'm using VS2012, latest available version of OpenAccess)

    Any help greatly appreciated,

    Regards,

    Chris

  2. Yordan
    Admin
    Yordan avatar
    39 posts

    Posted 09 Jul 2013 Link to this post

    Hi Chris,

    When a vertical inheritance is used every class has its own table containing only its fields. In your scenario when an "Update database from model" is clicked an SQL script should be executed against the database creating two tables - PostalLocation and CustomerSite. In CustomerSite table there should be an Id column derived from PostalLocation as described in this how to tutorial - this id column is used when a relation between PostalLocation and CustomerSite is created.

    If an error stating that an "Extraneous Id Column ..." appears please try to delete and recreate the relation between the classes. This should resolve the discrepancy created probably by other previous actions on the model.

    If you want to add OpenAccess service it is important that you save and built the project. To be able to select every class in the "Add Open Access Service" wizard the class should be mapped to a database table, you can just use default mapping.

    Please find attached an example how a vertical inheritance in your scenario could be made. In case you encounter any issues implementing the described steps please get back to us. If you can send us a sample project where the error occurs it will make it easier for us to find the right solution.
     

    Regards,
    Yordan
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvementsshipped with this release.

  3. DevCraft banner
  4. Chris
    Chris avatar
    3 posts
    Member since:
    Nov 2012

    Posted 09 Jul 2013 Link to this post

    Thanks for the reply, Yordan (and apologies for the duplicate post!)

    I downloaded the sample you provided and it worked as expected.

    But I think I've found the trigger for this odd behaviour.  To replicate:

    • Start with the project you attached to your reply.
    • Add an empty ASP.Net web application project (so you can select it in the OpenAccess wizard)
    • Open the rlinq designer, right-click the surface and choose Show Model Settings
    • Switch to the Code Generation tab.
    • Under Code Generation Options, change the mapping type to Attributes
    • Check all five of the checkboxes in that section

    Then rebuild the solution.  With an empty database, choose Update Database From Model to generate the script for the database.  Apply that script, rebuild again, then try to add an OpenAccess service.  The entity will not be selectable with an error described in my first post.

    I'd prefer to use attributes rather than separate XML, and all of the options that I'd select under Code Generation seem desirable.  But it seems that either they're not behaving how I'd expect, or I'm misunderstanding something!

    Thanks again for your help,
    Chris
  5. Yordan
    Admin
    Yordan avatar
    39 posts

    Posted 11 Jul 2013 Link to this post

    Hello Chris,

    We followed the described steps and reproduce the behavior of not being able to check the entities in the Add OpenAccess Service wizard. The problem is in that an attribute mapping is used. It turned out that with attribute mapping the fore-mentioned wizard could not recognize the entities in the model and cannot display them as enabled for selection. 
    If it is possible you should change the type of your mapping to XML in order to work around this issue. You can do that by opening the Model Settings via context menu Show Model Settings, going to Code Generation tab and selecting XML for the Mapping type.
    If you insist on using attributes mapping, please let us know what are the reasons so we can see what can be done in this direction.
    In order to use Attributes mapping you can use a second work around - manually edit the generated code (I assume you are trying to create Data Service v3). You can add one or more new lines with SetEntitySetAccessRule method calls in the EntitiesModel.svc.cs file, InitializeService method:
    1.public static void InitializeService(DataServiceConfiguration config)
    2.{
    3.    config.SetEntitySetAccessRule("DomainClass1", EntitySetRights.All);
    4.    config.SetEntitySetAccessRule("DomainClass2", EntitySetRights.All);
    5.    // ... add more entities here
    6.     
    7.    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    8.}

    Please note that this change will be overwritten if you run Add OpenAccess Service wizard in the same project again.

    Thank you for describing the exact steps that lead to this undesired behavior.

    Regards,
    Yordan
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvementsshipped with this release.

  6. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 18 Dec 2013 Link to this post

    Hello Chris,

    We have shipped a fix for the issue you have described using Add OpenAccess Service wizard and Attributes mapping. You can find the updated assemblies in the Q3 2013 SP1 release of OpenAccess. For more information about the release see our change log.

    If you experience any issues with the new version please let us know.

    Regards,
    Viktor Zhivkov
    Telerik
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Back to Top
DevCraft banner