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

Read Database schema at Runtime to generate metadata

2 Answers 55 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Catalin
Top achievements
Rank 1
Catalin asked on 08 Jan 2013, 01:25 PM
Hi,

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 Answers, 1 is accepted

Sort by
0
Accepted
PetarP
Telerik team
answered on 11 Jan 2013, 04:05 PM
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);
                    reader.Execute();
                    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.

Regards,
Petar
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
0
Catalin
Top achievements
Rank 1
answered on 11 Jan 2013, 04:11 PM
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


Tags
Data Access Free Edition
Asked by
Catalin
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Catalin
Top achievements
Rank 1
Share this question
or