Read Database schema at Runtime to generate metadata

3 posts, 1 answers
  1. Catalin
    Catalin avatar
    2 posts
    Member since:
    Aug 2012

    Posted 08 Jan 2013 Link to this post


    If possible, I would like to use the OpenAccess API to read the database schema and generate a metadata model at runtime, then persist the model (.rlinq) to disk.
    The reason I need to do this is because the database is extremely large (1200+ entities in 8+ schemas) and using the designer is not feasible. Also we have some complex rules for generating entity names based on table names and schema names that must be respected. Therefore the model must be processed programatically before it is used to generate classes from it.

    What API should I use to read the Database Schema into a Metadata container and save it to disk?

    I've searched the entire documentation, and the internet, but could not find how this can be accomplished.

    With kind regards,
    Catalin Pop
  2. Answer
    PetarP avatar
    754 posts

    Posted 11 Jan 2013 Link to this post

    Hello Catalin,

     It is possible to read the schema at runtime and get a metadata container out of it. In order to do that you will need to have an OpenAccessConnection (you can obtain one from the context) and do this:

    MetadataContainer container = null
    using (DbConnection dbCon = context.Connection)
                        var reader = DbSchemaReader.Create(dbCon);
                        container = reader.MetadataContainer;

    Unfortunately the serialization to an rlinq file is internal functionality and is not publicly accessible. It is not impossible to access it via reflection however we would strongly advice against that and you should be better off if you write your own serialization procedure.

    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
  3. DevCraft banner
  4. Catalin
    Catalin avatar
    2 posts
    Member since:
    Aug 2012

    Posted 11 Jan 2013 Link to this post

    Thank you Petar,

    This is what I was looking for.
    In regards to serialization I will begin writing my own procedure as at first glance doesn't seem to be highly complicated.

    With kind regards,
    Catalin Pop

Back to Top