Skip to content

DB Providers

Wade Baglin edited this page Feb 1, 2016 · 8 revisions

PetaPoco supports the following providers: SQL Server, SQL Server CE, MS Access, SQLite, MySQL, MariaDB, PostgreSQL, Firebird DB, and Oracle.

SQL Server

This is the default provider.

MS Access

This MS access provider will work with both the Jet and Ace OLEDB providers. The only item which isn't supported is the query paging API calls. The reason for this is because the lack of paging syntax support by MS Access means a generic method to take a query and page it is very problematic.

SQLite

Because of SQLite's simplified datatypes model, you will probably need to help PetaPoco map types. Is this possible via a registered mapper or using the newer fluent configuration.

    var builder = DatabaseConfiguration.Build()
        .UsingConnectionStringName("sqlite")
        .UsingDefaultMapper<ConventionMapper>(m =>
        {
            m.FromDbConverter = (targetProperty, sourceType) =>
            {
                if (targetProperty != null && sourceType == typeof(long))
                {
                    var type = !targetProperty.PropertyType.IsNullableType()
                        ? targetProperty.PropertyType
                        : targetProperty.PropertyType.GetGenericArguments().First();

                    switch (Type.GetTypeCode(type))
                    {
                        case TypeCode.DateTime:
                            return o => new DateTime((long) o, DateTimeKind.Utc);
                        default:
                            return o => Convert.ChangeType(o, Type.GetTypeCode(type));
                    }
                }

                return null;
            };
            m.ToDbConverter = sourceProperty =>
            {
                var type = !sourceProperty.PropertyType.IsNullableType()
                    ? sourceProperty.PropertyType
                    : sourceProperty.PropertyType.GetGenericArguments().First();

                switch (Type.GetTypeCode(type))
                {
                    case TypeCode.DateTime:
                        return o => ((DateTime) o).Ticks;
                }

                return null;
            };
        });

    var db = builder.Create();

SQL Server CE

Nothing note worthy

MySQL and MariaDB

Nothing note worthy

PostgreSQL

Nothing note worthy

Firebird DB

A recent addition to PetaPoco and is currently in beta

Oracle

Currently, there are no integration tests being run against an Oracle DB instance. We have plans to add this soon.