This is a migrated thread and some comments may be shown as answers.

Get field length from entity field

1 Answer 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
RICHARD FRIEND
Top achievements
Rank 2
RICHARD FRIEND asked on 06 May 2009, 10:24 AM
Im trying to get the field length from an entity field with a user control that will be bound inside a FormView.

Thus far i have the following, however im having trouble reflecting 

OpenAccessEnhancedStateManager

Any ideas or better approach..( maybe grab from config??)

private static volatile IDictionary<Type, IDictionary<string, int>oaMaxLenCache = new Dictionary<Type, IDictionary<string, int>>();  
        public static int GetOpenAccessMaxLength(Control cf,string fieldName)  
        {  
            int maxLen = -1;  
            IDataItemContainer nc = cf.NamingContainer as IDataItemContainer;  
            if (nc != null)  
            {  
                object di = nc.DataItem;  
                if (di != null)  
                {  
                    Type t = di.GetType();  
                    if (!oaMaxLenCache.ContainsKey(t)) { oaMaxLenCache.Add(t, new Dictionary<string, int>()); }//Add dict for type  
                    if (oaMaxLenCache[t].ContainsKey(fieldName))  
                    {  
                        //Load from cache  
                        maxLen = oaMaxLenCache[t][fieldName];  
                    }  
                    else  
                    {  
                        PropertyInfo fi = t.GetProperty("OpenAccessEnhancedStateManager",BindingFlags.Public); //Doesnt get the property...?? not sure why  
                        if (fi != null)  
                        {  
                            OpenAccessRuntime.DataObjects.PCStateMan sm = (OpenAccessRuntime.DataObjects.PCStateMan)fi.GetValue(di,null);  
                            if (sm != null)  
                            {  
                                OpenAccessRuntime.metadata.FieldMetaData stateField = sm.owner.stateFields.Where(m => m.name == fieldName).SingleOrDefault();  
                                if (stateField != null)  
                                {  
                                    OpenAccessRuntime.Relational.metadata.RelationalField fld = stateField.storeField as OpenAccessRuntime.Relational.metadata.RelationalField;  
                                    if (fld != null)  
                                    {  
                                        maxLen = fld.mainTableCols[0].length;  
                                        oaMaxLenCache[t].Add(fieldName, maxLen);//Store in cache  
                                    }  
                                }  
 
                            }  
                        }  
                    }  
                }  
            }  
            return maxLen;  
        } 

1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 06 May 2009, 01:27 PM
Hi RICHARD FRIEND,
Maybe you want to use this approach:

ClassMetaData

 

[] cmds = Telerik.OpenAccess.Debug.ModelHelper.GetModel(scope1);
foreach

 

(ClassMetaData cmd in cmds)
{
    Console.WriteLine("Class: " + cmd.Namespace + "." + cmd.Name);
    foreach (FieldMetaData fmd in cmd.GetFields())
        Console.WriteLine(" Field: " + fmd.Name + "(" + fmd.ColumnName + "(" + fmd.Length + "))");
}

 

You have to link against Telerik.OpenAccess.Runtime

All the best,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
RICHARD FRIEND
Top achievements
Rank 2
Answers by
Jan Blessenohl
Telerik team
Share this question
or