New Posts New Posts RSS Feed: Redundant PropertyMetadata classes
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Redundant PropertyMetadata classes

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Redundant PropertyMetadata classes
    Posted: 31-Aug-2011 at 3:15pm
In a few places, we inherit from some of our Entities.  Something very straightforward like:
public class FancyEmployee : Employee
{
   // Extra logic here
}
However, that isn't enough.  We've found that we need to re-delcare the PropertyMetadata nested class in our FancyEmployee.....even though we aren't adding any more properties.  So our code becomes less straightforward:
public class FancyEmployee : Employee
{
   public new class PropertyMetadata : Employee.PropertyMetadata
   {
         //This class is necessary to make Dev Force happy - otherwise serves no purpose :-)
    }

   // Extra logic here
}
If we don't do that, DevForce will just happily assume there are no properties!  Which I actually think is worse behavior than you used to have in previous versions where you would explicitly throw an exception saying "EntityType: FancyEmployee is not a valid 'Entity' subclass. It inherits from Entity but does not contain a PropertyMetadata nested type."  - at least that error told us that we were doing something wrong instead of silently ignore it.

It's not terribly complicated to have these extra PropertyMetadata classes but it does add some extra boilerplate code that is easy to forget.  Also, we have complicated inheritance hierarchies and we've started running into some weird errors cause by bad copy/pasting in the boilerplate code.  For example, the new PropertyMetadata class in FancyEmployee might accidentally inherit from Order.PropertyMetadata.  That kind of thing may work at first but eventually can come back to bite you.  Also, if we add a new class to our hierarchy, we have to be careful that we also update all these PropertyMetadata class so they inherit correctly.

I'm wondering if there might be a way that DevForce could do some kind of 'FlattenHierarchy' when it uses reflection to find the PropertyMetadata class.  That way we would only need to re-delcare it if we were actually adding properties (which is considerably more rare).
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 01-Sep-2011 at 11:46am
Hi Stephen,
 
If you create the child entity in the Designer, you won't have this problem.
 
As for when you manually create a child class, I am adding a feature request so it would automatically inherit PropertyMetadata.
 
Regards,
Silvio.


Edited by sbelini - 01-Sep-2011 at 11:46am
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Posted: 01-Sep-2011 at 4:19pm
Thanks!  Entities from the designer are fine.....it's the manually created ones that you mention that cause us problems.  We have lots of these that aren't technically database backed but we want 99% of our app to treat them like all our other Entities so we have them inherit from a real Entity.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down