Extend EntityField2

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 01-Aug-2007 06:32:07   

Is there a recommended way to add functionality, like a new property, to the fields exposed by an entity? The current way we do this is by inheriting off EntityField2 and changing the EntityFieldFactory template to create these inherited classes instead of EntityField2. However, we are in the process of coming up with a migration strategy going from 1.0.2005.1 to 2.0 and have the opportunity to try a better way, a better way meaning without changing LLBLGen's default templates (this was a major mistake the first go around).

Oh, this goes for EntityBase2, EntityFields2, and EntityField2. EntityBase2 seems to have a way to do this with a task built in the 3rd party area, but I don't see anything for EntityFields2 or EntityField2.

Any suggestions?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Aug-2007 08:35:57   

You have 2 options: 1- Modify the code generation templates/ 2- Use Partial Classes (.NET 2.0)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 01-Aug-2007 10:38:39   

what kind of property do you want to add and what's the reason for it?

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 01-Aug-2007 16:54:01   

Otis wrote:

what kind of property do you want to add and what's the reason for it?

There's per-user security metadata that can come along for each field/entity/entitycollection. For example, for a given field, there can be "Allow Read" and "Allow Update" which get set for the specific user. This metadata can probably be acquired via a service, but it seems less natural to go this route.

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 01-Aug-2007 16:59:53   

Walaa wrote:

You have 2 options: 1- Modify the code generation templates/ 2- Use Partial Classes (.NET 2.0)

Wouldn't I have to add these partial classes directly to the ORMSupportClasses? I guess I would be fine with this as long as it would be easy to do dll updates for bug fixes, but this seems like it would end up being a bit of a pain as I would always need to incorporate my partial class files in with the ORMSupportClasses sourcecode and recompile.

I suppose this is better than futzing with the templates, though.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Aug-2007 17:16:49   

I think all what you need is already implemented in v.2.5 (a free upgrade, beta is available & soon to be released).

Please check the Authorization feature in v.2.5

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 01-Aug-2007 17:44:04   

Walaa wrote:

I think all what you need is already implemented in v.2.5 (a free upgrade, beta is available & soon to be released).

Please check the Authorization feature in v.2.5

Just looking through the 2.5 documentation and ORMSupportClasses interfaces, I don't see a way to directly ask if a user can read or write to a field. I see that the authorizer can prevent a read or write, but don't see where you can do something like:

myEntity.Fields(myEntityFields.SomeField).AllowEdit

This would be necessary in order to disable a textbox bound to that field, for example.

Is this possible with the new authorization scheme?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Aug-2007 10:28:38   

I think you can call the inner public methods of the Authorizer as follows.

myEntity.AuthorizerToUse.CanGetFieldValue(...) & CanSetFieldValue(...), passing the fieldIndex of the field to check.

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 02-Aug-2007 16:47:15   

Walaa wrote:

I think you can call the inner public methods of the Authorizer as follows.

myEntity.AuthorizerToUse.CanGetFieldValue(...) & CanSetFieldValue(...), passing the fieldIndex of the field to check.

It looks like you need to pass in the entity for this to work, so you would have to make a call like myEntity.AuthorizerToUse.CanGetFieldValue(myEntity, fieldIndex)

This isn't horrible, but seems like it is more cumbersome than it needs to be. It would be great to just need to call:

myEntity.CanGetFieldValue(fieldIndex) or myEntity.Fields(fieldIndex).CanGetFieldValue()

Although its a bit late to request new features at this point, I'd like to request that there be interface elements on the Entity and EntityField which delegate to these callls to the AuthorizerToUse.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 04-Aug-2007 14:04:28   

if(myEntity.AuthorizerToUse!=null) { myEntity.AuthorizerToUse.Can... (); }

simple_smile

Frans Bouma | Lead developer LLBLGen Pro