Print Page | Close Window

Redundant PropertyMetadata classes

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2941
Printed Date: 21-Jan-2026 at 8:43pm


Topic: Redundant PropertyMetadata classes
Posted By: stephenmcd1
Subject: Redundant PropertyMetadata classes
Date 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).



Replies:
Posted By: sbelini
Date 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.


Posted By: stephenmcd1
Date 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.



Print Page | Close Window