Managed properties for BusinessBase objects only?

Managed properties for BusinessBase objects only?

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


ajj3085 posted on Wednesday, July 23, 2008

Hi,

It seems like the answer is obvious, but are managed properties pretty much geared only toward use in BusinessBase classes?  The only reason I'd see to use managed properties in ReadOnlyBase objects is to get the automatic CanReadProperty check done.   Or should they not be used at all in ROBs?

Andy

skagen00 replied on Wednesday, July 23, 2008

Hi Andy,

We're using managed properties in our read-only classes.

Doing a quick look at the Csla's ReadOnlyBase shows a FieldManager there.

Chris

 

ajj3085 replied on Wednesday, July 23, 2008

Chris,

Ya, I did see you could.  I guess I was just wondering what best practices would be.

RockfordLhotka replied on Thursday, July 24, 2008

I suggest always using RegisterProperty() and the GetProperty(), etc. helpers.

Whether you use a private backing field or managed backing field is a different question. Private backing fields are faster, but require a tiny bit more code. Managed backing fields require less code, but are slower.

Managed backing fields work automatically with CSLA Light. Private backing fields require that you write OnGetState() and OnSetState() methods to serialize/deserialize the values of those fields (just like in VB6) because reflection isn't workable in Silverlight (or medium trust in general).

Personally, I default to using managed backing fields for all objects, and only switch to private backing fields if I find performance to be an issue (which honestly hasn't happened yet in any real work).

ajj3085 replied on Thursday, July 24, 2008

I guess I'm missing something; I thought you had to use managed fields to use RegisterProperty and GetProperty. 

So will (has) the PTracker sample have it's read only BOs changed to use RegisterProperty and GetProperty?

RockfordLhotka replied on Thursday, July 24, 2008

It will ultimately use a mix of private backing fields and managed backing fields – so I can demonstrate both.

 

Rocky

 

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Thursday, July 24, 2008 7:36 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Managed properties for BusinessBase objects only?

 

I guess I'm missing something; I thought you had to use managed fields to use RegisterProperty and GetProperty. 

So will (has) the PTracker sample have it's read only BOs changed to use RegisterProperty and GetProperty?


skagen00 replied on Thursday, July 24, 2008

Hey Rocky, quick question.

You've said that managed fields are slightly slower when not using private backing.

How much slower? Have you run benchmarks or is it more of a "it's slower just by nature of design" but not exactly quantified at this point?

Thanks!

RockfordLhotka replied on Thursday, July 24, 2008

It depends on the situation (how many fields, are you in tight loops, etc), but it can be about 15-20% slower or so.

 

It has been a while since I did the testing – I was doing mass loading of objects with random data. If I recall correctly, it was loading around 10,000 objects per second with managed fields, and 12,000 with private backing fields – but this is totally from memory.

 

But it is slower by nature of design. Managed backing fields are stored in a data structure (array) rather than a private field, so there’s an array lookup to get/set the value rather than directly manipulating a single field.

 

Rocky

 

 

From: skagen00 [mailto:cslanet@lhotka.net]
Sent: Thursday, July 24, 2008 8:56 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: Managed properties for BusinessBase objects only?

 

Hey Rocky, quick question.

You've said that managed fields are slightly slower when not using private backing.

How much slower? Have you run benchmarks or is it more of a "it's slower just by nature of design" but not exactly quantified at this point?

Thanks!



sixeyes replied on Saturday, August 02, 2008

I'm new to CSLA. I'm using CSLA 3.5 and have been working with classes derived from ReadOnlyBase.

I've probably missed something but I found there was no LoadProperty in ReadOnlyBase and so as far as I could see the only way to use RegisterProperty etc in ROB was to use a private backing field.

Is there any way to use managed fields in ROB classes?

Iain

RockfordLhotka replied on Saturday, August 02, 2008

ReadOnlyBase should provide GetProperty(), ReadProperty() and LoadProperty() methods – the only one it doesn’t implement is SetProperty().

 

Rocky

 

 

From: sixeyes [mailto:cslanet@lhotka.net]
Sent: Saturday, August 02, 2008 6:55 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Managed properties for BusinessBase objects only?

 

I'm new to CSLA. I'm using CSLA 3.5 and have been working with classes derived from ReadOnlyBase.

I've probably missed something but I found there was no LoadProperty in ReadOnlyBase and so as far as I could see the only way to use RegisterProperty etc in ROB was to use a private backing field.

Is there any way to use managed fields in ROB classes?

Iain


sixeyes replied on Saturday, August 02, 2008

Ah!
When I started I didn't know about LoadProperty(), only SetProperty() / GetProperty () and was confused when I couldn't use SetProperty() in ROB.
As the ROB classes in Project Tracker don't use RegisterProperty() I assumed they didn't work there.

Much later I discovered LoadProperty() but for some reason assumed it wasn't in ROB.

Thanks for the clarification.

Iain

Copyright (c) Marimer LLC