OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.23k stars 2.34k forks source link

Add new database provider (Oracle) #1325

Open jpiquot opened 6 years ago

jpiquot commented 6 years ago

Hi, I need to add a new database provider for oracle databases but it seems that the store initialization is hardcoded. I can add a new provider but it will result in a store initialization error.

Could we put the initialization code as part of the DataProvider so the Store initialization uses it ?

Regards, Jérôme Piquot Flexmind France

OrchardCore.Data.ServiceCollectionExtensions.cs :
       public static IServiceCollection AddDataAccess(this IServiceCollection services)
        {
            services.AddScoped<IDataMigrationManager, DataMigrationManager>();
            services.AddScoped<IModularTenantEvents, AutomaticDataMigrations>();

            // Adding supported databases
            services.TryAddDataProvider(name: "Sql Server", value: "SqlConnection", hasConnectionString: true);
            services.TryAddDataProvider(name: "Sqlite", value: "Sqlite", hasConnectionString: false);
            services.TryAddDataProvider(name: "MySql", value: "MySql", hasConnectionString: true);
            services.TryAddDataProvider(name: "Postgres", value: "Postgres", hasConnectionString: true);

            // Configuring data access

       services.AddSingleton<IStore>(sp =>
            {
                var shellSettings = sp.GetService<ShellSettings>();

                if (shellSettings.DatabaseProvider == null)
                {
                    return null;
                }

                var storeConfiguration = new Configuration();

                // Disabling query gating as it's failing to improve performance right now
                storeConfiguration.DisableQueryGating();

                switch (shellSettings.DatabaseProvider)
                {
                    case "SqlConnection":
                        storeConfiguration.UseSqlServer(shellSettings.ConnectionString, IsolationLevel.ReadUncommitted);
                        break;
                    case "Sqlite":
                        var shellOptions = sp.GetService<IOptions<ShellOptions>>();
                        var option = shellOptions.Value;
                        var databaseFolder = Path.Combine(option.ShellsApplicationDataPath, option.ShellsContainerName, shellSettings.Name);
                        var databaseFile = Path.Combine(databaseFolder, "yessql.db");
                        Directory.CreateDirectory(databaseFolder);
                        storeConfiguration.UseSqLite($"Data Source={databaseFile};Cache=Shared", IsolationLevel.ReadUncommitted);
                        break;
                    case "MySql":
                        storeConfiguration.UseMySql(shellSettings.ConnectionString, IsolationLevel.ReadUncommitted);
                        break;
                    case "Postgres":
                        storeConfiguration.UsePostgreSql(shellSettings.ConnectionString, IsolationLevel.ReadUncommitted);
                        break;
                    default:
                        throw new ArgumentException("Unknown database provider: " + shellSettings.DatabaseProvider);
                }
sebastienros commented 6 years ago

I would suggest that we try refactor this code to make it extensible. When we manage to move at least one in an external module (as a test) then this issue should be fixed. It will require YesSql to have an Oracle provider first.

jpiquot commented 6 years ago

Hi Sebastien, Yes, I was thinking that the provider would not be too much work as YesSql uses Dapper that supports Oracle. The only issue is that there is no official .Net Core provider for Oracle. I have too options: 1) Use OrchardCore targetting net461 2) Use a third party .Net Core Oracle Provider I will try next week all these.

hishamco commented 6 years ago

Adding Oracle to YesSql & thinking about database extensibility here may allow things much easier

hishamco commented 5 years ago

Related to this https://github.com/sebastienros/yessql/issues/81

pbros commented 5 years ago

Hello,

I have been evaluating Orchard Core, but would like to use Oracle DB.

Oracle has released a provider for .NET Core (https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/2.18.6), and also a EntityFramework provider (currently still in Beta) (https://www.nuget.org/packages/Oracle.EntityFrameworkCore/2.18.0-beta3)

Have there been any updates for supporting Oracle?

Thank you

hishamco commented 5 years ago

IMHO we should wait until the RTM release

pbros commented 5 years ago

Hi @hishamco does Orchard use Entity Framework? If so I agree, but if not, the Oracle.ManagedDataAccess.Core is an RTM release. I was in beta earlier last year.

Jetski5822 commented 5 years ago

No, it uses YesSQL. Shouldn’t be too hard to write a provider for it.

Do you know the license?

Sent from my iPhone

On 10 Apr 2019, at 22:13, pbros notifications@github.com wrote:

Hi @hishamco does Orchard use Entity Framework? If so I agree, but if not, the Oracle.ManagedDataAccess.Core is an RTM release. I was in beta earlier last year.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

hishamco commented 5 years ago

I think we need to close this issue, and better track it in YesSql sebastienros/yessql#81

Piedone commented 4 years ago

This can be left open so once the YesSQL issue is resolved we can continue with this one. However, I think Oracle DB support at most can be on some best effort basis, not on part with the other providers.