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 typeOracle.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()**