The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Adding columns at runtime (AKA User Defined Fields)

Last post 10-08-2008, 4:39 PM by leonidbogdanov. 2 replies.
Sort Posts: Previous Next
  •  03-25-2008, 3:46 PM 8548

    Adding columns at runtime (AKA User Defined Fields)

    Our configuration is ES 2007.1.1210.0, SQL Server 2005, we use dynamic sql.

    Different clients of our application require slightly different sets of columns stored in the database. So, we will provide an option to add a column at runtime. We don’t assume any special logic involved with those fields, their intention is to store data. The program is a webservice that mainly selects/inserts/updates data in the database. I've done some testing, and it looks like with some little modifications ES can gracefully handle database columns added at runtime.

    1. A new column metadata should be added to the columns metadata collection. This is doable right now because esColumnMetadataCollection implements Add() method.
    2. Provider type map should be updated to include a new map. esProviderSpecificMetadata.AddTypeMap() works great.
    3. Parameters cache needs to be updated to include new column. At the moment, there is no way to refresh this cache. I think the easiest way to implement this is to check if the number of metadata columns is different from the number of parameters in the cache (inside the Cache.GetParameters method). If the number is different, then recreate parameters.
    4. SetProperty method requires some rework to check if the property is not a generated one, but is listed in the metadata columns, then use one of the SetSystemInt32(), SetSystemString(), etc. methods to set the value.
    5. On serialization/deserialization side, using XmlAnyElement attribute allows accept/emit XmlElements for columns that where added at runtime.

    I may be missing something, please point on mistakes. It would be great to have this all built into the framework.

    Thank you,

    Leonid

  •  03-28-2008, 6:47 PM 8623 in reply to 8548

    Re: Adding columns at runtime (AKA User Defined Fields)

    Let us get this beta out this weekend and then have a closer look at this, I agree it's a very valuable feature.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  10-08-2008, 4:39 PM 11846 in reply to 8623

    Re: Adding columns at runtime (AKA User Defined Fields)

    Is it possible to make the following 2 changes in the next release:

    1. 

    Replace the following code at the beginning of the SqlClientProvider.Cache.GetParameters() method:

                lock (parameterCache)

                {

                    if (!parameterCache.ContainsKey(dataID))

                    {

    with

                lock (parameterCache)

                {

     

                    bool refreshCache = !parameterCache.ContainsKey(dataID);

                    // If the number of metadata columns is different from what we have in cache,

                    // recreate parameters cache.

                    if (!refreshCache)

                        refreshCache = columns.Count != parameterCache[dataID].Count;

     

                    if (refreshCache)

    2. Add 'Delete' method to the  esColumnMetadataCollection

     

    First is more important.

    Thank you,

    Leonid

     

     

View as RSS news feed in XML