Dynamically Creating a Field

Posts   
 
    
Posts: 112
Joined: 09-Aug-2004
# Posted on: 26-May-2005 19:37:22   

We had a database with alot of lookup tables (ie State Lookup Table, Credit Card Look Up table). We generalized All of these tables to two simple tables. One of the tables stores the generic name value pairs. Both name/value are varchar's because in some instances we will store chars and in other we will store ints.

At run time we can't do databinding because the tables which store the foreign key value store them as mostly as ints.

So basically I need to add an integer type field to my collection at run time if I know it's values are ints.

Whew... I hope this is readable.

Currently my solution is to put it out to a datatable



public DataTable GetCodesAsIntegersInDataTable(int CodeTypeID){
    filter = new PredicateExpression();
    filter.Add(new PredicateExpression(PredicateFactory.CompareValue(BLMaster.CodesFieldIndex.CodeTypeId, ComparisonOperator.Equal, CodeTypeID)));

    DataTable dt = GetMultiAsDataTable(filter, 0, sorter);
    dt.Columns.Add(new DataColumn("CodeCodeInt", typeof(System.Int32), "CodeCode"));
                
    return dt;

}

So this works because I can bind with CodeCodeInt. 

I would like to see if it is possible to still use the collection itself while doing the same thing. Any Ideas?


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 27-May-2005 11:33:33   

Override in your entity, GetProperties.

First call the base method. This will give you property descriptors in a PropertyDescriptorCollection (it's ICustomTypeDescriptor.GetProperties). You then should add a property descriptor for your field. You can use EntityPropertyDescriptor (or EntityPropertyDescriptor2) for that. It's a bit complex, but I think it's doable.

Frans Bouma | Lead developer LLBLGen Pro