1

Is there any library for .NET that allows user to manipulate database schema from code using the same code for different DB providers?

I built my own utility library that allows me to create or alter tables or columns but I wonder if there is already such a library. One that also includes constraints and indexes.

I use something like this:

DBManager db = new DBManager(connString);
DBTable persons = new DBTable("Persons");
orders.Columns.Add(new DBColumn("Name", DBType.Varchar, 100);
orders.Columns.Add(new DBColumn("Birthday", DBType.Date);
db.CreateTable(persons);
db.AddColumn("Persons", new DBColumn("CityID",DBType.Int);
db.DropColumn("Persons", "Birthday");

Of course, this isn't hardcoded. I want to add a feature to my application to allow users to specify they own entities that can be stored in database and then my app will use the library to create the underlying database table.

2
  • if you have your own utility why are you looking for one that exists elsewhere? Which database are you using (mysql, mssql, pgsql?) Commented Feb 13, 2011 at 9:27
  • As I asked, I want support for multiple providers and management for constraints and indexes. Also, such library requires diverse skills, more than one person can handle. Commented Feb 13, 2011 at 11:52

2 Answers 2

1

I only know how to query database schema from code using the same code for different DB providers.

Since dotnet 2.0 most dotnet-providers implement System.Data.Common.DbConnection .

With the System.Data.Common.DbConnection.GetSchema() function (without parameter) you can ask the provider which collectionNames it supports (tables, views, stored procedures, .....) These can be used with GetSchema(collectionName) to get more details. Among the details are even supported datatypes and regular expressions to validate fieldnames.

You can also look at the MyGeneration project source . Its mymeta engine builds a common api around different databaseproviders.

NHibernate must have something like a common database-provider as well. But i havent looked at its sourcecode yet.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the SQL Server Management Objects http://msdn.microsoft.com/en-us/library/ms162169.aspx

If it is SQL Server you are working with of course...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.