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

Discriminator Column issue (Reverse Mapping)

4 Answers 95 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alfred Ortega
Top achievements
Rank 2
Alfred Ortega asked on 20 May 2009, 04:11 PM
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

4 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 21 May 2009, 08:22 AM
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.
0
Alfred Ortega
Top achievements
Rank 2
answered on 21 May 2009, 01:22 PM

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

0
Alexander
Telerik team
answered on 21 May 2009, 01:48 PM
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.
0
Alfred Ortega
Top achievements
Rank 2
answered on 21 May 2009, 02:50 PM
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
Tags
Development (API, general questions)
Asked by
Alfred Ortega
Top achievements
Rank 2
Answers by
Alexander
Telerik team
Alfred Ortega
Top achievements
Rank 2
Share this question
or