Accessing Field Metadata Programmatically

5 posts, 0 answers
  1. Eric Villemure
    Eric Villemure avatar
    19 posts
    Member since:
    Feb 2008

    Posted 27 Feb 2009 Link to this post

    Hi,

    Is there a way to get field metadata properties programmatically?
    For example, instead of hard coding a length, we would like to be able to set the maximum length of a text field based on the length of the database field. e.g. if I have a column called PersonName in the dadabase datatype=nvarchar(16), then in the text box displaying the name, I want to set the MaxLength to 16 in the code behind instead of hard code the control's property in the aspx page. This way, if the database definition changes, I don't have to manually set the value in each aspx page.

    Thank you in advance, Eric.
  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 02 Mar 2009 Link to this post

    Hello Eric Villemure,
    There is not a fully supported way at the moment. You have to reference the Telerik.OpenAccess.Runtime.dll and use the static method:

    Telerik.OpenAccess.Debug.ModelHelper.GetModelFor(scope)

    Find your class and field and select the length and scale properties.

    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.
  3. DevCraft banner
  4. Eric Villemure
    Eric Villemure avatar
    19 posts
    Member since:
    Feb 2008

    Posted 02 Mar 2009 Link to this post

    Thank you for the quick answer.
    I was able to use GetModel() to get the field length from the field metadata like this:
                ClassMetaData[] metadata1 = Telerik.OpenAccess.Debug.ModelHelper.GetModel(scope);  
                ClassMetaData positionMetadata = metadata1.First(ClassMetaData => ClassMetaData.Name == "Position");  
                FieldMetaData fieldMetaData = positionMetadata.GetFields().First(FieldMetaData => FieldMetaData.ColumnName == "UserCode");  
                int length = fieldMetaData.Length;  
                textBox1.MaxLength = length; 

    I've got some questions related to this:
    1. GetModel() is mark Obsolete. Is there another method we should use instead?
    2. All the metadata related methods are not documented, are you planning on documenting them in the future?
    3. Do you have plans to introduce another way to get this information e.g. by using attributes for each field.

    Thanks, Eric.
  5. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 03 Mar 2009 Link to this post

    Hello Eric Villemure,
    The API is not documented at the moment because it is internal API that is used by a couple of customers only.

    To remember this we have the Obsolete attribute. It is the only way at the moment to get these information and you should just use it.

    The properties of the persistent classes are your code, what ever attribute you place there is fine with OpenAccess.

    The metadata API is not yet on the roadmap. But we will try to make it really public because it is very useful.

    Regards,
    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.
  6. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 03 Mar 2009 Link to this post

    Hi,

    Yes, yes, yes :-) It's absolutely neccessary.

    Regards
    Tomasz
Back to Top
DevCraft banner