This is a migrated thread and some comments may be shown as answers.
Managed collection for overridden property
1 Answer 42 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Denis Vulinovich
Top achievements
Rank 1
Denis Vulinovich asked on 07 Nov 2009, 07:59 PM
I want to set up a managed collection using a property that is overridden in a derived class, but the Forward Mapping dialog doesn't provide that option.

My application is for an industrial control system that uses many types of devices, such as sensor and push buttons. A sensor can be located anywhere in the factory, but a push button must be located on a control panel. Other devices, including sensors, can also be located in a control panel.

To implement this, I have a Device class with a Location property, and Sensor and PushButton classes are derived from it. In the Push Button class the Location property is overridden so that it can only be set to a Panel object. The Panel class contains a collection of PushButtons, plus a separate collection of Devices.

In the Forward Mapping dialog, if I set the Mapping Relationship for the Panel _pushButtons field to 1:n, the Inverse Field is {auto} but the Manage Collection option is not available. Below that, the DB Column Name appears as id2, and in the database an id2 column is added to the PushButton table, even though it doesn't appear in App.config.

When I build the project, I get a warning "Generation of duplicate column name attempted for reference field 'Panel__pushButtons' of class 'Integrator.System.PushButton'". Maybe this is because it's getting confused between Panel's PushButtons and Devices collections?

1 Answer, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 09 Nov 2009, 10:29 AM
Hi Denis,

Did you name (the column name) the reference from Device to Location?

If not, it is what is causing your warning since the id of the Location instance referenced by the Device instance, will result in a foreign key column in the table mapped to the Device class, say T_Device. OA will name this automatically (to id2) if you have not done so in the forward mapping settings.
However, the Device class has subclasses which also needs foreign keys (you have a collection of PushButton from Panel class). This collection (since it is 1:m without a mapping table) will result in an foreign key column in the child class table, which is the table mapped to the PushButton class, say T_PushButton. OA will also name this Id2 and thus you are getting ambiguous names.

If you name the reference from Device to Location to for example fk_location you should not get the warning.

How did you map the inheritance between Device and say PushButton?

Regards

Henrik
Tags
General Discussions
Asked by
Denis Vulinovich
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Share this question
or