C# 无法将sql/oracle数据库转换为system.data.entity.database
我正在尝试将应用程序从.net framework 2.0升级到4.71,但由于无法将sql/oracle数据库转换为system.data.entity.database,因此出现错误 代码如下:C# 无法将sql/oracle数据库转换为system.data.entity.database,c#,.net,visual-studio-2017,C#,.net,Visual Studio 2017,我正在尝试将应用程序从.net framework 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
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”
只有在为发布配置设置解决方案时才会引发错误,如果是调试配置,则会消失。如何修复此问题?您正在转换错误的基类型数据库 您正在获取System.Data.Entity.Database,它应该位于Microsoft.Practices.EnterpriseLibrary.Data.Database的位置 尝试删除名称空间System.Data.Entity并使用Microsoft.Practices.EnterpriseLibrary.Data,或指定数据库的完整名称空间
小问题。这只有在我将其设置为调试配置时才有效。如果我将其设置为Release,它将抛出以下错误-严重性代码描述项目文件行抑制状态错误CS0234命名空间“Microsoft.Practices.EnterpriseLibrary”中不存在类型或命名空间名称“Data”是否缺少程序集引用?
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.");
}