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

Accessing Field Metadata Programmatically

4 Answers 100 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eric Villemure
Top achievements
Rank 1
Eric Villemure asked on 27 Feb 2009, 09:27 PM
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.

4 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 02 Mar 2009, 09:15 AM
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.
0
Eric Villemure
Top achievements
Rank 1
answered on 02 Mar 2009, 11:25 PM
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.
0
Jan Blessenohl
Telerik team
answered on 03 Mar 2009, 12:51 PM
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.
0
tmlipinski
Top achievements
Rank 1
answered on 03 Mar 2009, 03:22 PM
Hi,

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

Regards
Tomasz
Tags
Development (API, general questions)
Asked by
Eric Villemure
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Eric Villemure
Top achievements
Rank 1
tmlipinski
Top achievements
Rank 1
Share this question
or