Multiple errors creating a one-to-one relationship with vertical inheritance.

3 posts, 1 answers
  1. Gary
    Gary avatar
    28 posts
    Member since:
    Jun 2015

    Posted 24 Aug 2015 Link to this post

    I have a database for forum-type postings which includes, among others, 2 tables defined with a one to one relationship. One table represents the basic fields for all postings, where as the other table adds fields for a specific type of post.

     

    01.CREATE TABLE [dbo].[PostingBase](
    02.    [posting_id] [bigint] IDENTITY(1,1) NOT NULL,
    03.    [post_title] [varchar](2550) NULL,
    04.    [original_publish_date] [datetime] NOT NULL,
    05.    [published_by] [nvarchar](255) NULL,
    06.    [publish_start_date] [datetime] NOT NULL,
    07.    [publish_expiration_date] [datetime] NOT NULL,
    08.    [is_enabled] [bit] NULL,
    09.    [is_published] [bit] NULL,
    10.    [created_date] [datetime] NOT NULL,
    11.    [created_by] [varchar](255) NOT NULL,
    12.    [updated_date] [datetime] NOT NULL,
    13.    [updated_by] [varchar](255) NOT NULL,
    14. CONSTRAINT [PK_PostingBase] PRIMARY KEY CLUSTERED
    15.(
    16.    [posting_id] ASC
    17.)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    18.) ON [PRIMARY]
    19. 
    20.GO
    21. 
    22. 
    23.CREATE TABLE [dbo].[AcademicDirectoryPostings](
    24.    [posting_id] [bigint] NOT NULL,
    25.    [region_id] [int] NULL,
    26.    [program_id] [bigint] NULL,
    27.    [degree_code] [varchar](10) NULL,
    28.    [post_content] [varchar](max) NULL,
    29.    [post_additional_info] [nvarchar](max) NULL,
    30.    [site_id] [int] NOT NULL,
    31.    [dept_id] [bigint] NOT NULL,
    32. CONSTRAINT [PK_AcademicDirectoryPostings] PRIMARY KEY CLUSTERED
    33.(
    34.    [posting_id] ASC
    35.)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    36.) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    37. 
    38.GO
    39. 
    40.SET ANSI_PADDING OFF
    41.GO
    42. 
    43.ALTER TABLE [dbo].[AcademicDirectoryPostings]  WITH CHECK ADD  CONSTRAINT [FK_AcademicDirectoryPostings_AcademicPrograms] FOREIGN KEY([program_id])
    44.REFERENCES [dbo].[AcademicPrograms] ([program_id])
    45.GO
    46. 
    47.ALTER TABLE [dbo].[AcademicDirectoryPostings] CHECK CONSTRAINT [FK_AcademicDirectoryPostings_AcademicPrograms]
    48.GO
    49. 
    50.ALTER TABLE [dbo].[AcademicDirectoryPostings]  WITH CHECK ADD  CONSTRAINT [FK_AcademicDirectoryPostings_PostingBase] FOREIGN KEY([posting_id])
    51.REFERENCES [dbo].[PostingBase] ([posting_id])
    52.ON UPDATE CASCADE
    53.ON DELETE CASCADE
    54.GO

     

    I created a Domain Model file (.rlinq) and imported the existing database schema. In the rlinq file I want to create a vertical relationship between the PostingBase and AcademicDirectoryPosting models. After following the instruction in the article ... ... the project indicates that it compiles successfully but the error window displayed errors and the rling file is identified as the source of the errors.
       
    The db-optimistic-locking option may only be specified for the least derived class in a hierarchy
    --> DbContext/namespace[DataAccess]/class[AcademicDirectoryPostingEntity]/db-optimistic-locking="changed" C:\Projects\Middle Tier\MT.v1\MT\DataAccess\Context\DbContext.rlinq


    The meta constraint 'FK_AcademicDirectoryPostings_PostingBase' contains a source column 'posting_id' which is not part of the source table 'AcademicDirectoryPostings'. C:\Projects\Middle Tier\MT.v1\MT\DataAccess\Context\DbContext.rlinq

    Class AcademicDirectoryPostingEntity has a persistence-capable-superclass so use the inheritance extension to specify its primary-key
    --> DbContext/namespace[DataAccess]/class[AcademicDirectoryPostingEntity] C:\Projects\\Middle Tier\MT.v1\MT\DataAccess\Context\DbContext.rlinq



    For the first error I followed the advice in the forum post ... How to: Create One-to-One Associations with Vertical Inheritance ... and changed the concurrency mode of the base class to "changed" and the concurrency mode of the derived class to "default". It did not seem to resolve the issue. 

    The second error, I assume was a result from when I deleted the primary key field from the derived class as instructed by the aforementioned instructions. When I deleted the primary key however, I was asked if I wanted to delete the associated column (which as not mentioned in the documentation). I tried it once and chose to NOT delete the associated column, That is when the error first appeared. I went back and manually re-added the property to the domain model and, using the Mapping Details Editor, I mapped the database column back to the property. This time when I was prompted to remove the column I answered "YES". No change. The project still built but the errors were still being reported in the error window. 

    The third error in the list I cannot really explain. I have been unable to find any information about "inheritance extensions" and have not been able to find any additional information on this error searching Google. 

    Any help that could be provided would be greatly appreciated!

    Thanks,
    G

  2. Gary
    Gary avatar
    28 posts
    Member since:
    Jun 2015

    Posted 24 Aug 2015 Link to this post

    I apologize for duplicating this post. The first post  returned an error so I rewrote the post, not realizing that it had actually posted.

    -G

  3. DevCraft banner
  4. Answer
    Ady
    Admin
    Ady avatar
    589 posts

    Posted 26 Aug 2015 Link to this post

    Hello Gary,

     No problem.
    I will reply to this issue in the original ticket that you created and will close this one to avoid confusion.

    Regards,
    Ady
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top