Update FieldPersistenceInfo TypeConverter at runtime

Posts   
 
    
rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 15-Dec-2010 00:31:21   

In my application i have the need to update the field typeconverter with a custom Typeconverter i have created. Not all the fields will be using this, only fields that are flagged in the database as such.

Please advice.

Thanks Ricardo

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Dec-2010 04:34:35   

Why do you want to do that at runtime? Please elaborate more so we can offer you an alternative. What LLBLGen version are you using?

David Elizondo | LLBLGen Support Team
rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 15-Dec-2010 04:39:58   

I have a Fields table in sql server that includes a list of all the available fields. In that table i have a IsEncrypted flag that will make the user select which of the fields will contain encrypted data.

Now i have it all working if i manually set the typeconverter using llblgen UI. I want to be able to do the same at runtime.

Version: LLBLGen Pro 3.0

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Dec-2010 05:56:35   

I can think about something you can do at runtime for this, other than create a method to set the field's value. You should do that in top of the LLBLGen generated code. The problem is that the fields are generated with a type, you can change that. So you should create some special method to set the value for you, maybe without TypeConverters. You could create a helper class that generically receives a field and a value, and set that in the field using a desired TypeConverter.

David Elizondo | LLBLGen Support Team
rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 15-Dec-2010 13:57:06   

That sounds great, but i need some guidance codewise. Will you give me step by step directions on how to achieve it. LLBLGen Pro is not my specialty.

Thanks Ricardo

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Dec-2010 15:42:00   

To encrypt a field, are you going to change it's type? I mean you need to alter the value of the field, not the type, right?

rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 15-Dec-2010 15:47:56   

I will not be altering the field datatype..The encrypted field will always be typeof(string) in .NET and nvarchar in the sql server database

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Dec-2010 16:06:17   

If you are not going to alter the type, then you should not use a typeConverter.

The encryption can be done anywhere else, such as in OnValidateEntityBeforeSave. Using a Validator.

rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 15-Dec-2010 16:26:37   

There are other variables involved that required the use of the typeconverter...The set of applications are exaustives and include reporting, front end, rules engines...

How would i implement the automatic set of typeconverter?

Ricardo

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 16-Dec-2010 09:51:27   

The info is shared among each instance of the field. Therefore you can't change it at runtime.

typeconverters can be a way to convert value X into value Y of the same type, however, they only get the type and value, no other info (as no other info is needed for the purpose they're designed for). If you therefore want to convert a value based on other values in the entity, you have to use different ways, i.e. with the On* methods to tap into the system.

With encryption it's really about: you either use it for a value, everywhere, or you don't. You can't simply say "when I read the row for this application, I don't have to use decryption", as the value in the DB is encrypted. So it's a concern of the client, not the server, if you want to make this flexible and 'on the fly'.

Frans Bouma | Lead developer LLBLGen Pro
rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 16-Dec-2010 13:42:31   

Otis,

Thank you for your response. Regarding the handles of encryption and when to encrypt/decrypt a string, all mechanism are implemented to ensure we know within the string content (using encryption signatures in strategic indexes of encrypted string) to allow us to make that decision in the TypeConverter.

Let me stress again, the fact that all this solution is fully implemented and working within our clients for months. The desire outcome of this post, was solely to create a way to assign the TypeConverter during runtime ( i am well openned to change the inside for the ORMSupportClasses project is a function is not available out of the box).

Currently for everytime we generate Code using the LLBLGen Pro 3.0 designer, we need to manually go to each of the fields that we want to be encrypted and set the TypeConverter.

This is seriously not a efficient way, prone to tons of human error, as we need to keep a list of encrypted fields separately and our clients list differ greatly as they not set on one industry.

The application know within its first line of executing code which fields are flagged to use encryption. We just need the solution to implement it on the fly.

Ricardo

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Dec-2010 21:37:03   

As we have stated a few times now, it is not currently possible to do what you require at runtime, and (Frans may correct me here) I doubt if it will become a feature anytime soon.

There are other solutions available which don't involve the use of TypeConverters - rather than trying to bend LLBLGen to do something it was not designed to do, you may be better off investigating an alternative solution.

Matt

rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 16-Dec-2010 21:54:19   

Is it at least possible to get the FieldPersistenceInfo object for a field?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Dec-2010 09:01:26   
var adapter = new DataAccessAdapter();
IFieldPersistenceInfo fieldInfo = adapter.GetFieldPersistenceInfo(myEntityField);
rmartins
User
Posts: 21
Joined: 15-Dec-2010
# Posted on: 17-Dec-2010 16:41:28   

That code didnt work...The function GetFieldPersistenceInfo is not avilable.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Dec-2010 00:17:32   

Sorry, that method is protected. To publish a method that return that info, write this in the CUSTOM_CODE_REGION of your DataAccessAdapter.cs file in your DBSpecific Project, or even better, in a partial class file.

public IFieldPersistenceInfo GiveMeTheFieldInfo(IEntityField2 f)
{
    return this.GetFieldPersistenceInfo(f);
}

Then you will be able to return that info.

var adapter = new DataAccessAdapter();
var fieldInfo = adapter.GiveMeTheFieldInfo(CustomerFields.ContactName);
David Elizondo | LLBLGen Support Team