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

Getting type by class id

1 Answer 51 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.
Markus
Top achievements
Rank 1
Markus asked on 21 Apr 2010, 04:37 PM
Is it possible to get type of persistent object by class id?

int classId = 123456;
System.Type t = context.GetType(classId);

I want to store a reference to an object type only not to an concrete object. Therefore I have a property "ClassID" of type int in my class. In GUI I want to display the name of the type, so I need to translate class id to type

Regards,

Markus

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 22 Apr 2010, 04:28 PM
Hello Markus,

You can achieve your goal by traversing our Metadata tree. In the metadata tree you will see that there is a collection of persistent types. That collection represents all your persistent classes and each of them has a property called ClassID. You can use that property in order to find the class you need.
The code for achieving this should look something similar to this:
MetadataContainer metadata = ObjectScopeProvider1.GetNewObjectScope().Database.MetaData;
           int classID = 1234;
           string className = metadata.PersistentTypes.Where(c => c.ClassId == classID).Select(c => c.Name).First();
If you are using our new Visual designer you can access the metadata via context.Metadata.
I hope that my answer has been useful to you. Please do not hesitate to contact us back if you have any further problems.

All the best,
Petar
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Development (API, general questions)
Asked by
Markus
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or