Getting type by class id

2 posts, 0 answers
  1. Markus
    Markus avatar
    40 posts
    Member since:
    Sep 2008

    Posted 21 Apr 2010 Link to this post

    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


  2. PetarP
    PetarP avatar
    754 posts

    Posted 22 Apr 2010 Link to this post

    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,
    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.
  3. DevCraft banner
Back to Top