Implementing an UpdateSchema provider is relatively simple. Implement the IUpdateSchemaProvider interface, add a constructor with a specific signature and, optionally, add one static method.
The update schema provider class must be decorated with an UpdateSchemaProvider attribute. The parameter is the XpoProviderTypeString for the XPO connection provider.
[UpdateSchemaProvider(AccessConnectionProvider.XpoProviderTypeString)]
public class AccessUpdateSchemaProvider : IUpdateSchemaProvider
{
}
The provider must have a constructor with a ConnectionString parameter. This connection string is the same connection string that you would use to connect to the XPO DataLayer or the XPO Session.
private OleDbConnection connection;
public AccessUpdateSchemaProvider(string connectionString)
{
ConnectionString = UpdateSchemaProviderHelper.RemoveXpoProviderTypeParameter(connectionString);
connection = new OleDbConnection();
}
Notice in the constructor that the connection is not opened here. Opening the connection should be performed in the Open() method.
The first parameter of each main functionality method (ModifyStringColumnSize, RenameColumn, DeleteColumn) is an UpdateSchemaOrder. This allows the provider to perform the functionality either before or after the XPO Schema Update. In fact you can implement a portion of the functionality before and another portion after the XPO Schema Update. Most of the time the RenameColumn will be done before the XPO Schema Update and the ModifyStringColumnSize and DeleteColumn will be done after the XPO Schema Update.
The additional static method DropDatabase is used during unit testing and may be useful in other instances This is a method is provided so that unit testing can run from a clean starting point. The DropDatabase method for the Microsoft Access provider is as follows:
public static bool DropDatabase(string connectionString)
{
return FileBasedProviderHelper.DropDatabase(connectionString);
}
This method uses a provider helper for file based providers. Both the Microsoft Access and VistaDB 3 providers are file based and use this static helper class.
All providers (apart from Microsoft SQL Server and Microsoft Access) should be placed in the DevExpressContrib.Xpo.UpdateSchema.Providers project.
You may, of course, use the current providers to help jump start creating a new provider. Both the Microsoft SQL Server provider and the VistaDB 3 provider took me a couple of hours to code up and test. The Microsoft Access provider took me a bit longer because RenameColumn was not a simple SQL statement. I imagine that a database which does not support renaming a column would take a few additional hours. It would probably have to be coded as a create new column, copy data from old column and then drop the old column.
If you write a provider for one of the databases that XPO supports, please consider contributing it to DevExpress Contrib.