9

I am using Entity Framework 4.4 code first(Factory Pattern) to get data from existing Oracle view. Here is my entity class:

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

Here is my Map class

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

Here is my context class

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

Now while I am writing this line in test class-

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

This select method gives me following error :

A null was returned after calling the get_ProviderFactory method on a store provider instance of type Oracle.DataAccess.Client.OracleConnection. The store provider might not be functioning correctly.

Please tell me where I am doing wrong! Also my connection-string looks as below:

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

Config file contents are mentioned above and here is the stack-trace:

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()**
CSDev
  • 3,177
  • 6
  • 19
  • 37
ucguy
  • 91
  • 1
  • 2
  • did you install the Oracle provider? btw. I am not sure if the Oracle provider shipped with ODP.NET supports CodeFirst. – Pawel Jun 10 '13 at 15:05
  • Actually I am using Oracle.DataAccess v2.112.1.0 assembly. I am doing rest the same as described [here]http://dotnetspeak.com/2012/01/oracle-odp-and-entity-framework-code-first-4-2). But when I use Oracle.DataAccess v4.112.3.0 it says: **Oracle.Access versoin is not supported with the installed provider. I have Oracle 11g installed in mechine.** Cant figure out the exact reason for this error! – ucguy Jun 11 '13 at 06:59
  • The exception indicates that the ODP.NET provider is not installed correctly. In general when a ADO.NET provider is installed it adds some entries to the machine.config. Without these entries ADO.NET cannot find the provider factory and therefore returns null. Have you tried connecting to the Oracle without EF? Did it work? Are you able to add a new Database First model? On a different note I did not realize it was CodeFirst to an existing database. This should work indeed. – Pawel Jun 11 '13 at 15:06
  • I have successfully connected oracle without EF through ODP.Net. No, I have not tried the Database First model. Actually when u see the **static constructor** of **Context** class, it makes this approach for existing database. – ucguy Jun 12 '13 at 06:40
  • In that case. Can you provide the stack trace and contents of your config file? – Pawel Jun 12 '13 at 14:40
  • I have given stack-trace in reply section because it was too long to accomodate in reply section. Please tell me if you can identify the error now, because I got no luck to resolve this issue by wandering across all websites – ucguy Jun 21 '13 at 08:59
  • To me it seems like your installation is broken since EF is not able to get the provider factory from the connection. Also you should not post a part of your question as an answer. – Pawel Jun 25 '13 at 00:02
  • Sometime you need to make sure that you have 32 v. 64 bit provider installed. I.e. it needs to match your app. – Sergey Barskiy Nov 14 '13 at 03:32

0 Answers0