Efficient Access to ActualDotNetType

Posts   
 
    
Posts: 98
Joined: 10-Nov-2006
# Posted on: 25-Apr-2013 20:32:45   

Using LLBLGen 4.0 Final, Self Servicing, .NET 4.5:

I'm upgrading my code to LLBLGen 4.0. As suggested by the documentation, I am trying to change all calls like entity.Fields[index].CurrentValue to entity.Fields.GetCurrentValue(index). In general this is working well, but there's one case I'm having trouble with.

I currently have a call like this:


var entity = GetMyEntity();
var index = 5;
var type  = entity.Fields[index].ActualDotNetType;

I'd like to do this without accessing .Fields[index] to get better performance. However, there's no GetActualDotNetType() on IEntityFields or IEntityFieldsCore. I did find that I can do this:

entity.Fields.GetAsPersistenceInfoArray()[index].ActualDotNetType

but it appears that GetAsPersistenceInfoArray() is cloning the array before returning it, so it seems like there might not be much performance improvement in that method over my original code.

Is there an efficient way get get the ActualDotNetType for a field?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 26-Apr-2013 00:26:40   

ActualDotNetType is a member of the EntityField class. You can access it directly using the EntityField. Did you find any performance issues using the EntityField?

Posts: 98
Joined: 10-Nov-2006
# Posted on: 26-Apr-2013 01:37:40   

No, I don't have any particular performance problems - I was just trying to remove my calls to .Fields[index], as suggested in the documentation.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Apr-2013 08:14:14   

That is different because ActualDotNetType is part of the field's persistence info, not a member of IEntityFieldsCore. What you can do is access the persistence info directly, something like this:

var type = customer.Fields.GetAsPersistenceInfoArray()[index].ActualDotNetType;
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Apr-2013 11:55:31   

That's indeed the way to do it. There's no handy shortcut implemented on IEntityFields for this, as in general one doesn't need it that much. I'm reluctant to alter the interface with a method for this at this point.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 10-Nov-2006
# Posted on: 26-Apr-2013 17:58:51   

Frans,

Thanks for confirming that I'm not missing some better way of doing this.

-Wesley