Inheriting a different base class question

Posts   
 
    
KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 15-Nov-2006 18:42:52   

Hello,

We are getting ready to upgrade to the new version in the next few weeks, and I have been asked to implement a validation framework where the client code, for example can ask an entity for any broken validation rules.

For example:


IBusinessRuleSet brokenRules = entity.Validate();

For me to achieve this, I am envisioning all my entities inherit from a new class, DomainObject, where I can add the necessary logic. Has anyone done this before and what steps I would need to follow?

Thanks!

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 15-Nov-2006 19:49:49   

It was somewhat of a pain, but to do this we had to modify the templates to inherit from our custom base class (which inherited from EntityBase2). From what I remember this amounted to going through each template and replacing each EntityBase2 with CustomEntityBase. This lead to problems upgrading templates, so much in fact that we rarely do it except for bug fixes which affect our application directly.

Had I to do it again, one possible way would have been to create a BrokenRulesManager and use it like:


BrokenRulesManager.Instance.GetBrokenRules(entity)

Another possible way is to write GetBrokenRules into the user defined part of the Entity template, but this seems like a bit too much of a hack to me as this code would be repeated in every single entity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 15-Nov-2006 20:34:18   

There's a custom set of templates available for v2.0 customers which adds a common base class between a generated entity and entitybase2. Please see the 3rd party section in v2.0's downloads.

Frans Bouma | Lead developer LLBLGen Pro
KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 15-Nov-2006 21:05:33   

Otis wrote:

There's a custom set of templates available for v2.0 customers which adds a common base class between a generated entity and entitybase2. Please see the 3rd party section in v2.0's downloads.

Thanks, you guys are always a step ahead!

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 15-Nov-2006 22:25:09   

KristianP wrote:

We are getting ready to upgrade to the new version in the next few weeks, and I have been asked to implement a validation framework where the client code, for example can ask an entity for any broken validation rules.

The entities implement the IError interface... This might work for you.

BOb

KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 15-Nov-2006 22:45:24   

PilotBob wrote:

KristianP wrote:

We are getting ready to upgrade to the new version in the next few weeks, and I have been asked to implement a validation framework where the client code, for example can ask an entity for any broken validation rules.

The entities implement the IError interface... This might work for you.

BOb

Can you pls elaborate?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 16-Nov-2006 09:18:00   

I think he meant the IDataErrorInfo interface, which is a .net interface for error reporting simple_smile

Frans Bouma | Lead developer LLBLGen Pro
PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 16-Nov-2006 18:20:47   

KristianP wrote:

PilotBob wrote:

KristianP wrote:

We are getting ready to upgrade to the new version in the next few weeks, and I have been asked to implement a validation framework where the client code, for example can ask an entity for any broken validation rules.

The entities implement the IError interface... This might work for you.

BOb

Can you pls elaborate?

Sorry, IDataErrorInfo interface as Frans states. This allows you while doing your validation to specify the Errors for each field and/or entity. This allows you to retrieve those error messages in another layer. This is very close to a broken rules type thing, but rather than a collection of brokenrules objects it is really just a string. But, it's 95% there.

BOb