ucg*_*guy 7 c# oracle entity-framework connection-string
我首先使用Entity Framework 4.4代码(工厂模式)从现有Oracle视图中获取数据.这是我的实体类:
class Data
{
[Required]
[StringLength(50)]
public String EmailAddress { get; set; }
[Required]
[StringLength(200)]
public String FundName { get; set; }
[Required]
[DecimalPrecision(AllowedPrecision=15,AllowedScale=0)]
public Decimal FundCode { get; set; }
[StringLength(3)]
public String BankCode { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的Map类
class DataMap : EntityTypeConfiguration<Data>
{
public DataMap() : base()
{
// Properties
Property(t => t.EmailAddress).HasColumnType("varchar2");
Property(t => t.FundName;
Property(t => t.FundCode
Property(t => t.BankCode).HasColumnType("varchar2");
// Table
ToTable("VIEW_FD_EMAIL");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的上下文类
class OracleContext : DbContext
{
static OracleDataEntities()
{
//Database.SetInitializer<DataEntities>(new SeedingIntitializer());
Database.SetInitializer<OracleContext>(null);
}
public OracleDataEntities()
: base(new OracleConnection(ConfigurationManager.ConnectionStrings["OracleConnection"].ConnectionString), true)
{
Configuration.ProxyCreationEnabled = false;
}
public DbSet<Data> MasterFund { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<ColumnTypeCasingConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new DataMap());
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在测试课上写这一行时 -
var rep = new DataRepository();
rep.Select(x => x).ToList();
Run Code Online (Sandbox Code Playgroud)
这个select方法给出了以下错误:
get_ProviderFactory
在类型的商店提供程序实例上调用方法后返回nullOracle.DataAccess.Client.OracleConnection
.商店提供商可能无法正常运行.
请告诉我我在哪里做错了!我的连接字符串如下所示:
<add name="OracleConnection" connectionString="Data Source=DDS ; User Id=112; Password=112;PERSIST SECURITY INFO=True;" providerName="Oracle.DataAccess.Client" />
Run Code Online (Sandbox Code Playgroud)
配置文件内容如上所述,这里是堆栈跟踪:
at System.Data.Common.DbProviderServices.GetProviderFactory(DbConnection connection)
at System.Data.Common.DbProviderServices.GetProviderServices(DbConnection connection)
at System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo (DbConnection connection, DbProviderManifest& providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at EFOracle.Program.Main(String[] args) in C:\Documents and Settings\adcwcxt\Desktop\EFOracle\EFOracle\Program.cs:line 16
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()**
Run Code Online (Sandbox Code Playgroud)