Managed collection for overridden property

Thread is closed for posting
2 posts, 0 answers
  1. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 07 Nov 2009 Link to this post

    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?
  2. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 09 Nov 2009 Link to this post

    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?


Back to Top