【问题标题】:cannot convert sql/oracle database to system.data.entity.database无法将 sql/oracle 数据库转换为 system.data.entity.database
【发布时间】:2018-03-29 16:31:09
【问题描述】:

我正在尝试升级应用程序(从 .net 框架 2.0 到 4.71),但由于无法将 sql/oracle 数据库转换为 system.data.entity.database 而出现错误。

代码如下:

using EntLibContrib.Data.OdpNet;
using Microsoft.Practices.EnterpriseLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;


public Database GetDatabase(string name)
    {
        UMiami.MedResearch.Core.ConnectionString str = this.Retrieve(name);
        if (str != null)
        {
            if (str.ProviderType == "SQL Server")
            {
                return new SqlDatabase(str.Value);
            }
            if (str.ProviderType == "Oracle")
            {
                return new OracleDatabase(str.Value);
            }
        }
        throw new Exception("Connection string was not found.");
    }

收到的错误是:

严重性代码描述项目文件行抑制状态 错误 CS0029 无法将类型“Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase”隐式转换为“System.Data.Entity.Database”

严重性代码描述项目文件行抑制状态 错误 CS0029 无法将类型“EntLibContrib.Data.OdpNet.OracleDatabase”隐式转换为“System.Data.Entity.Database”

只有在我为 Release 配置设置解决方案时才会引发错误,如果是 Debug 配置则消失。我该如何解决这个问题?

【问题讨论】:

    标签: c# .net visual-studio-2017


    【解决方案1】:

    您正在转换错误的基本类型 `DataBase。

    你得到了System.Data.Entity.Database,它应该是Microsoft.Practices.EnterpriseLibrary.Data.Database

    尝试删除命名空间System.Data.Entity并使用Microsoft.Practices.EnterpriseLibrary.Data,或者将完整的命名空间指定为Database

    using EntLibContrib.Data.OdpNet;
    using Microsoft.Practices.EnterpriseLibrary;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    // replace to the right namespace
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
    
    
    public Database GetDatabase(string name)
    {
         UMiami.MedResearch.Core.ConnectionString str = this.Retrieve(name);
         if (str != null)
         {
             if (str.ProviderType == "SQL Server")
             {
                 return new SqlDatabase(str.Value);
             }
             if (str.ProviderType == "Oracle")
             {
                 return new OracleDatabase(str.Value);
             }
         }
         throw new Exception("Connection string was not found.");
    }
    

    【讨论】:

    • 小问题。仅当我将其设置为调试配置时才有效。如果我将其设置为发布,则会引发以下错误 - 严重性代码描述项目文件行抑制状态错误 CS0234 名称空间“Microsoft.Practices.EnterpriseLibrary”中不存在类型或名称空间名称“数据”(您是否缺少程序集参考?)
    猜你喜欢
    • 1970-01-01
    • 2020-07-08
    • 2014-02-06
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2011-10-27
    • 2011-02-01
    • 2016-09-18
    相关资源
    最近更新 更多