Skip to content

DB Providers

Aaron Sherber edited this page Sep 21, 2018 · 8 revisions

PetaPoco supports by default the following providers: SQL Server, SQL Server CE, MS Access, SQLite, MySQL, MariaDB, PostgreSQL, Firebird DB, and Oracle. You can also create your own custom provider.

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.

Oracle

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