Use the mymeta component to obtain the database structure

Source: Internet
Author: User

Use the mymeta component to obtain the database structure

The mymeta component is one of the core modules of the Automatic Code Generation Tool mygeneration. It is mainly responsible for defining and obtaining the relational database structure. Mymeta defines a complete set of Relational Database Object Structures and provides methods to obtain (reverse engineering) these objects. Using mymeta, you can easily obtain metadata of most types of objects in the database. These objects include schema), tables, views, stored procedures, indexes, columns, primary keys, foreign keys, stored procedure parameters, etc. Although the object types in relational databases are not limited, for our general software development, this information is sufficient. In addition, mymeta also supports enough relational database types. It can be said that all the database systems available on the market support them, it includes MS Access, ms SQL Server, Oracle, MySQL, DB2, Firebird, PostgreSQL, pervasive, SQLite, and vistadb, and can be flexibly expanded. Of course, mygeneration is all open-source, which is also an important reason why I finally decided to use mymeta in the project.

The usage of mymeta is also very simple. After adding a reference to mymeta. DLL to the project, you can use the following code to obtain the structure of the entire database:


Code
String connstring = "Data Source = Forrest; persist Security info = true; user id = orauser; Password = orauserpwd ";

Mymeta. dbroot root = new mymeta. dbroot ();
Root. showdefadatabdatabaseonly = true;

Root. Connect (mymeta. dbdriver. Oracle, connstring );

Foreach (mymeta. Database dB in root. databases)
Console. writeline ("database {0} has {1} tables and {2} views. ", DB. Name, DB. Tables. Count, DB. Views. Count );

Mymeta. dbroot is one of the most important types when using mymeta. It is the root for accessing database objects. All database schema objects can be accessed through the dbroot. Databases collection.

I found two problems during usage. One is that the showdefadatabdatabaseonly attribute of dbroot does not seem to work. Whether set to true or false, every time I obtain all the databases that the login user has the permission to view; second, when connecting to the ms SQL Server, the description of the column in the view cannot be obtained, that is, the value of the extended attribute ms_description of the column. These two problems refer to the bug in the source code tracing and debugging. After the source code is modified and re-compiled, the system runs normally. Mygeneration Official Website: http://www.mygenerationsoftware.com/portal/default.aspx Selection process:

The latest project has the function of obtaining database metadata. The requirement is not high: to obtain the column information of tables and views, including description information (comment in Oracle, ms_description in SQL Server ); supports multiple types of databases. I immediately thought of a large number of Automatic code generation tools on the Internet. Getting database meta information is a required feature of the Automatic code generation tool. I only need this. Codesmith, codemaker, codeplus, and nowind. after enterpriseorm and mygeneration, from the perspective of reusing the database metadata to obtain components, some of the first four must be licensed, some support less database types, and some modules and levels are unclear and not suitable for reuse, finally, mymeta of mygeneration is selected. In fact, codesmith is the most famous component. The component that provides this function is schemaexplorer. The structure design is very reasonable and the scalability is also very strong. I plan to use it. However, it was later found that it does not support the description information and does not support Oracle enough. It does not support views, and the latest version must be registered before it can be used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.