Writing new data stores

The core Neo library provides a multi layered API to write new data stores.

Implementation from scratch

The most general, and flexible, approach is to implement the IDataStore interface which comprises only two methods:

public interface IDataStore
{
    DataTable FetchRows(IFetchSpecification fetchSpec);
    ICollection SaveChangesInObjectContext(ObjectContext context);
}

That said, implementation of these methods for databases is quite complex.

Implementations for data providers

If an ADO.NET data provider exists for the data source it is usually easier to subclass DbDataStore, which implements IDataStore, and provide implementations for the following two interfaces:

public interface IDbImplementationFactory
{
    IDbConnection CreateConnection(string connectionString);
    IDbCommand CreateCommand();
    IDbDataAdapter CreateDataAdapter();
    IDataParameter CreateParameter(DataColumn pcolumn, string pname, object pvalue);
    IDbCommandBuilder CreateCommandBuilder(DataTable table);
}

public interface IDbCommandBuilder
{
    void WriteSelect(IFetchSpecification fetchSpec);
    void WriteInsert(DataRow row, IList columnList);
    void WriteUpdate(DataRow row);
    void WriteDelete(DataRow row);
    
    string Command { get; }
    IList Parameters { get; }
}

These interfaces contain more methods but should be easier to implement than the IDataStore interface.

Implementations for SQL databases

The GenericSql92Builder provides a good starting point for implementing the IDbCommandBuilder interface if the database in question is a SQL database. In this case only deviations of the database-specific SQL syntax from the SQL92 standard need to be handled; this usually involves support for fetch limits.

See the Oracle and SQL Server store implementations for an example of this strategy.

If your database needs delimited identifiers, note that the GenericSql92Builder has support for this. It can be turned on by setting the UsesDelimitedIdentifiers property to true. If you need delimiters other than double quotes you can override the converter method.

Labels

 
(None)