Help! Another business base inheritance issue.

Help! Another business base inheritance issue.

Old forum URL: forums.lhotka.net/forums/t/5431.aspx


dctc42 posted on Thursday, September 18, 2008

Property metadata is not registered properly if I do the following:

class A : BusinessBase<A>

{

      Property1;

}

 

class B : A

{

   Property2;

}

If I instatiate B Property2 is registered under type A in the property info manager. RegisterProperty uses typeof(T) to register the property and of course typeof(T) is A when creating an instance of B.

GetPropertyList(typeof(B)) is not returning what I need and is causing all sorts of hell to break loose.

How do I solve this?

 

Thanks

dctc42 replied on Thursday, September 18, 2008

There's an override that lets me pass in the type!

What a freakout over nothing Smile [:)]

See you all later. I have a lot searching and replacing to do...

 

skagen00 replied on Thursday, September 18, 2008

Be sure to remember the _dummy flag in your "A" class, otherwise you'll have a common problem reported quite frequently here. If you don't know what I'm talking about, just ask.

I kinda figured initially when I read your post it had to do with that, but it looks like you may have found something else. Whenever I see inheritance and property info together in the same point that's what I assume you're running into.

dctc42 replied on Friday, September 19, 2008

I'm afraid I don't know about the dummy flag. What is it for?

 

Thanks

skagen00 replied on Friday, September 19, 2008

Managed properties of base classes that you inherit from _will not work reliably_ if you do not utilize one of two options.

The option I use and the one noted as the preferable one to use is this:

First, you need to declare a static variable in your base class. (The pragma is to avoid FxCop messages, you don't need that).

#pragma warning disable

private static int _dummy;

#pragma warning restore

Then, in the constructor of your base class, you need to "touch" this variable.

protected MyBaseClass()

{

   _dummy = -1;

}

You will also need to touch it in the OnDeserialized override.

protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)

{

   _dummy = 1; // Required for static properties.

}

It's obviously kind of a pain to have to do this, but unfortunately no other options have been discovered. This is only required when you're using inheritence in your BOs and you have managed properties in a base class.

If you're not already doing this, then I wager that your problem you're experiencing is exactly this.

 

dctc42 replied on Friday, September 19, 2008

The problem I was having was related to property metadata fields. When I called PropertyInfoManager.GetPropertyList the list it was incomplete (it did not include property metadata for base classes).

It's good to know about the _dummy hack but I'm not using managed properties so I think it doesn't apply to me at this time.

Thanks for the info.

jasonlaw replied on Thursday, September 18, 2008

Hi dctc42,
May I know how you resolve the issue?
Thank you.

dctc42 replied on Friday, September 19, 2008

JasonLaw,

I had to use the override of RegisterProperty that takes an explicit type parameter for all business objects that don't directly inherit from BusinessBase<T>.

I can't confirm this fixed everything, I had to change 364 property definitions (macros rule!). I'm in the process of writing unit tests to confirm all is well.

Copyright (c) Marimer LLC