用oracle安装nopcommerce

时间:2015-05-29 16:05:21

标签: oracle nopcommerce

你好,我下载了解决方案nopCommerce一个电子商务开源,这个成就运行和安装没有问题与MSSQLSERVER数据库但是我想用ORACLEdatabase实现

官方网站http://www.nopcommerce.com/

我一直在指导这篇文章 http://www.nopcommerce.com/boards/t/17712/mysql-support.aspx

我已经尝试按照mysql指示的步骤进行操作并适应oracle但是首先告诉我的是创建两个类的事情之一

OracleConnectionFactory:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.Infrastructure;
using System.Data.Common;
using Oracle.DataAccess.Client;



namespace Nop.Data
{
public class OracleConnectionFactory : IDbConnectionFactory
{
    private readonly string _baseConnectionString;
    private Func<string, DbProviderFactory> _providerFactoryCreator;

    public OracleConnectionFactory()
    {
    }

    public OracleConnectionFactory(string baseConnectionString)
    {
        this._baseConnectionString = baseConnectionString;
    }

    public DbConnection CreateConnection(string nameOrConnectionString)
    {

        string connectionString = nameOrConnectionString;

        bool treatAsConnectionString = nameOrConnectionString.IndexOf('=') >= 0;

        if (!treatAsConnectionString)
        {
            OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder(this.BaseConnectionString);
            //MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(this.BaseConnectionString);

            //builder.Server = nameOrConnectionString;
            connectionString = builder.ConnectionString;
        }

        DbConnection connection = null;

        try
        {
            connection = this.ProviderFactory("Oracle.DataAccess.Client").CreateConnection();
            connection.ConnectionString = connectionString;
        }
        catch
        {
            //connection = new MySqlConnection(connectionString);
            connection = new OracleConnection(connectionString);
        }
        return connection;
    }

    public string BaseConnectionString
    {
        get
        {
            return this._baseConnectionString;
        }
    }

    internal Func<string, DbProviderFactory> ProviderFactory
    {
        get
        {
            Func<string, DbProviderFactory> func1 = this._providerFactoryCreator;
            return delegate(string name)
            {
                return DbProviderFactories.GetFactory(name);
            };
        }
        set
        {
            this._providerFactoryCreator = value;
        }
    }
 }
}

OracleProvider:

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Web.Hosting;
using Nop.Data.Initializers;
using Oracle.DataAccess.Client;
using Nop.Core.Data;


namespace Nop.Data
{
public class OracleDataProvider : IDataProvider
{
    #region Utilities

    protected virtual string[] ParseCommands(string filePath, bool throwExceptionIfNonExists)
    {
        if (!File.Exists(filePath))
        {
            if (throwExceptionIfNonExists)
                throw new ArgumentException(string.Format("Specified file doesn't exist - {0}", filePath));
            else
                return new string[0];
        }


        var statements = new List<string>();
        using (var stream = File.OpenRead(filePath))
        using (var reader = new StreamReader(stream))
        {
            var statement = "";
            while ((statement = readNextStatementFromStream(reader)) != null)
            {
                statements.Add(statement);
            }
        }

        return statements.ToArray();
    }

    protected virtual string readNextStatementFromStream(StreamReader reader)
    {
        var sb = new StringBuilder();

        string lineOfText;

        while (true)
        {
            lineOfText = reader.ReadLine();
            if (lineOfText == null)
            {
                if (sb.Length > 0)
                    return sb.ToString();
                else
                    return null;
            }

            //MySql doesn't support GO, so just use a commented out GO as the separator
            if (lineOfText.TrimEnd().ToUpper() == "-- GO")
                break;

            sb.Append(lineOfText + Environment.NewLine);
        }

        return sb.ToString();
    }



    #endregion

    #region Methods

    public virtual void InitConnectionFactory()
    {
        //var connectionFactory = new SqlConnectionFactory();
        var connectionFactory = new OracleConnectionFactory();
        //TODO fix compilation warning (below)
        #pragma warning disable 0618
        Database.DefaultConnectionFactory = connectionFactory;
    }

    /// <summary>
    /// Initialize database
    /// </summary>
    public virtual void InitDatabase()
    {
        InitConnectionFactory();
        SetDatabaseInitializer();
    }

    /// <summary>
    /// Set database initializer
    /// </summary>
    public virtual void SetDatabaseInitializer()
    {
        //pass some table names to ensure that we have nopCommerce 2.X installed
        var tablesToValidate = new[] { "Customer", "Discount", "Order", "Product", "ShoppingCartItem" };

        //custom commands (stored proedures, indexes)

        var customCommands = new List<string>();
        //use webHelper.MapPath instead of HostingEnvironment.MapPath which is not available in unit tests
        customCommands.AddRange(ParseCommands(HostingEnvironment.MapPath("~/App_Data/Install/SqlServer.Indexes.sql"), false));
        //use webHelper.MapPath instead of HostingEnvironment.MapPath which is not available in unit tests
        customCommands.AddRange(ParseCommands(HostingEnvironment.MapPath("~/App_Data/Install/SqlServer.StoredProcedures.sql"), false));

        var initializer = new CreateTablesIfNotExist<NopObjectContext>(tablesToValidate, customCommands.ToArray());
        Database.SetInitializer(initializer);
    }

    /// <summary>
    /// A value indicating whether this data provider supports stored procedures
    /// </summary>
    public virtual bool StoredProceduredSupported
    {
        get { return true; }
    }

    /// <summary>
    /// Gets a support database parameter object (used by stored procedures)
    /// </summary>
    /// <returns>Parameter</returns>
    public virtual DbParameter GetParameter()
    {
        //return new SqlParameter();
        return new OracleParameter();
    }

    #endregion
 }
}

我也安装了像这个链接所说的托管nuget包 http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/CodeFirst/index.html

oracle odp.net托管驱动程序

在nop.data和nop.web

我感谢任何有助于我完成我需要做的或我可能要去的步骤的帮助

我尝试的第一件事是Oracle提供程序识别并实现连接到我的数据库

1 个答案:

答案 0 :(得分:2)

这是一个有趣的问题。在技​​术上可以使用与Oracle的nop商务,但对你来说这将是一个非常疯狂的旅程。

首先是好消息。 Nop Commerce基于存储库模式进行架构。基本上Nop.Data抽象所有与SQL Server相关的数据访问。你需要几乎完全重写它。

接下来不是那么好消息。搜索,分页,目录列表使用SQL Server中的存储过程。您可能需要完全重写它。而且大多数时候,你都独自一人。除非你对Oracle和.Net EF有信心,否则这将是一个非常疯狂的过程。

我想说,如果你想坚持使用SQL Server,问题就少了。我知道有时您可能无法做出技术决定。因此,您可以清楚地解释迁移到此人所需的复杂性和工作量。

资料来源:NopCommerce开发人员最近2。5年。