9

我首先使用 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; }
}

这是我的地图课

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");
    }
}

这是我的上下文类

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());
    }
}

现在,当我在测试课上写这行时-

var rep = new DataRepository();
rep.Select(x => x).ToList();

这种选择方法给了我以下错误:

get_ProviderFactory在类型为 的商店提供程序实例上调用该方法后返回 null Oracle.DataAccess.Client.OracleConnection。商店提供程序可能无法正常运行。

请告诉我哪里做错了!我的连接字符串也如下所示:

  <add name="OracleConnection" connectionString="Data Source=DDS ; User Id=112; Password=112;PERSIST SECURITY INFO=True;" providerName="Oracle.DataAccess.Client" />

上面提到了配置文件内容,这里是堆栈跟踪:

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()**
4

0 回答 0