Discriminator Column issue (Reverse Mapping)

5 posts, 0 answers
  1. Alfred Ortega
    Alfred Ortega avatar
    193 posts
    Member since:
    May 2005

    Posted 20 May 2009 Link to this post

    I've read through the documentation on using a discriminator column (flat-mapping) and I just have one issue left to resolve, but first here's what I'm looking at.

    DBTable
    (
     ID int identity(1,1) PK
    --other fields here..
    pageType nvarchar(5) NOT NULL      --THIS IS THE DISCRIMINATOR COLUMN
    )

    Now in the App.Config I have added this as per the documentation into the base class:

                <extension key="db-class-id" value="0">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="page_Type" />
                  </extension>
                </extension>

    In the App.Config the inherited class has:
              <class name="InheritedClass1Name">
                <extension key="db-class-id" value="PAAN" />
              </class>


    I can read records just fine, but when I attempt to add a record I get an Exception saying that the discrimiator column is in the insert statement twice.  The inherited classes have nothing unique to it, no data members on it's own.  What am I doing wrong?

    Thanks in advance,
    Al
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 21 May 2009 Link to this post

    Hello Alfred Ortega,

    I did not succeed in reproducing the problem even though i used the same configuration. Are you sure that you have set the exact name of the discriminator column in the App.config file? You said that the column specification is "pageType nvarchar(5) NOT NULL" but you have "<extension key="db-column-name" value="page_Type" />" in the configuration. Another thing that could possibly cause problems is if you are trying to use reverse mapping initially. Is that the case or you are using forward mapping only?

    Sincerely yours,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Alfred Ortega
    Alfred Ortega avatar
    193 posts
    Member since:
    May 2005

    Posted 21 May 2009 Link to this post

    I'm honestly not sure if it is configured correctly that is what I'd like to better understand.  When I do select statements or LINQ it works fine.  As far as page_type vs pageType Page_Type is the name of the column in the DB, pageType is the mapped member name. I think that part is okay because on the exception message for the insert it shows the sql and Page_Type is in their twice - which is the problem.

    I did reverse mapping to generate the code for the base class and hand coded the the other classes and updates to the app.config.  Then I tested it by running a few select/linq statements and everything worked as expected - until I tried inserting a record.  In the app.config, since I have a field mapped and a discriminator column set in the base class could this be why it's showing up twice?

     

    Al

  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 21 May 2009 Link to this post

    Hello Alfred,

    Yes, I think this is the problem. The discriminator column should not be mapped, it is used internally. When having it mapped, OpenAccess tries to store the field value in the relevant column and at the same time another mechanism is trying to set the class-id there. You do not experience problems with reading because OpenAccess just reads the value from the page_Type column and populates the mapped field. So the solution here should be to remove the mapped pageType field/property and the related information for this field from the App.config and Reversemapping.config files.

    Greetings,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Alfred Ortega
    Alfred Ortega avatar
    193 posts
    Member since:
    May 2005

    Posted 21 May 2009 Link to this post

    It worked great - THANK YOU.  I would like to suggest that in the documentation that covers the discriminator column not only have the xml adjustments to the config but some class diagrams as well.

    Thanks again,
    Al
Back to Top
DevCraft banner