【发布时间】:2015-12-02 10:38:31
【问题描述】:
是否可以创建一个代码优先的实体框架模型,该模型使用 ODP.Net 连接到现有数据库,而无需在 app.config 文件中进行任何设置?
我尝试了很多不同的东西。
目前我正在设置 DbConfiguration:
sealed class EntityFrameworkConfiguration : DbConfiguration
{
public static readonly DbConfiguration Instance = new EntityFrameworkConfiguration();
EntityFrameworkConfiguration()
{
this.SetDefaultConnectionFactory(new OracleConnectionFactory());
this.SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
}
}
DbConfiguration.SetConfiguration(EntityFrameworkConfiguration.Instance);
我将 OracleConnection 直接传递到 EF 上下文中。
但是,我以 SQL Server 格式生成的 SQL 出现问题(在表别名周围使用双引号),或者我收到以下错误:
An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
Additional information: Unable to determine the provider name for provider factory of type 'Oracle.ManagedDataAccess.Client.OracleClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
有没有人在不使用 crud 污染 app.config 的情况下让它工作的经验?
【问题讨论】:
标签: oracle entity-framework entity-framework-6 odp.net