Example of Dynamic Fields in Entity

Posts   
 
    
Posts: 23
Joined: 13-Oct-2005
# Posted on: 20-Jan-2006 19:03:39   

Could someone point me to a sample of generated Entity code (C# preferred) that has been modified to support dynamic fields?

I have an Entity that can have additional fields. I'd like to be able to show those fields/values in a bindable control. But I don't understand what to do to extend the existing interfaces with my dynamic fields.

Thanks, Bill

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-Jan-2006 09:29:28   

What exactly do you mean with 'Dynamic fields' ? Fields which aren't defined in the class but in some sort of array/list inside the entity?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 23
Joined: 13-Oct-2005
# Posted on: 23-Jan-2006 15:27:26   

Yes, exactly. I have an entity with a number of fixed fields, but it may have "custom" fields that are stored elsewhere in the database. I'm trying to augment the code so that when binding controls interrogate the entity, it provides a combined list of fields, and their values.

As a further complication, if the entities are in a collection, each entity may have a different set of custom fields. The need for this to work for collections is less important than the individual entity case.

Thanks, Bill

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Jan-2006 16:42:28   

I can only think of using SQL Server 2005 to have an XML field which will hold future attributes & values.

Please chek this thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4885 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4577

Posts: 23
Joined: 13-Oct-2005
# Posted on: 23-Jan-2006 16:59:53   

I've reviewed those treads, and they describe a creative solution for accomidating custom fields in the database. I happen to be doing it a different way, but that's not the purpose of my thread...

What I want to know is how to sub-class or customize the generated Entity object so that those custom fields (regardless of how they are persisted) are exposed right along with the list of static fields in an instance of an entity.

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 24-Jan-2006 04:43:24   

Bill,

Take a look at this page in the LLBLGen Pro.chm:

Generated code - Custom properties

It describes how to add custom properties to your entities or collections in the designer. I don't believe this fully answers your question so I'm going think on this somemore...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Jan-2006 09:56:03   

It's kind of difficult, unless you create a property hardcoded in your class, but that'snot what you want of course.

To get the custom fields show up in a grid as columns, propertydescriptors for these fields have to be created at runtime. I'm not sure what you're using, selfservicing or adapter. In selfservicing it's a little 'easier' than in adapter.

In selfservicing a PropertyDescriptorFactory is used for collections. See FactoryClasses\PropertyDescriptorFactory.cs. This class produces the propery descriptors in GetPropertyDescriptors. If you modify that class (for example by writing your own or modifying the template) you can produce different properties and for example produce propertydescriptors for your custom properties.

Keep in mind that PropertyDescriptorFactory will be removed in v2.0.

Frans Bouma | Lead developer LLBLGen Pro