ef 6.x oracle,c# – 使用EF 6和Oracle.ManagedDataAccess时表不存在

我正在使用EF 6.0.0.0和ODP.Net创建一个MVC应用程序Oracle.ManagedDataAccess版本4.121.2.0用于数据访问.

在我的名为EmployeeController的Controller中,我有以下代码片段:

public ActionResult Details(int id) {

try {

EmployeeContext employeeContext = new EmployeeContext();

Employee employee = employeeContext.Employees.Single(x => x.Id == id); //Here the exception occurs!

return View(employee);

} catch (Exception e) {

return View(e);

}

}

当我加载Employee / Details.cshtml页面时,我得到以下异常:

“An error occurred while executing the command definition. See the

inner exception for details.”

在内部异常中,它说:

ORA-00942: table or view does not exist

这让我很困惑,因为在我的Oracle数据库中,该表肯定存在(我使用Toad for Oracle检查):

yVlBf.png

数据库本身的connectionString是我用于其他项目的连接字符串,我可以毫不费力地从数据库中查询数据.

以下是我在MODEL / Employee.cs中声明我的Employee类的方法:

using System.ComponentModel.DataAnnotations.Schema;

.

.

.

[Table("TBLEMPLOYEE")] //the same table name

public class Employee {

public int Id { get; set; }

public string Name { get; set; }

public string Gender { get; set; }

public DateTime DateOfBirth { get; set; }

public int EmployeeType { get; set; }

public double? AnnualSalary { get; set; }

public double? HourlyPay { get; set; }

public double? HoursWorked { get; set; }

public string City { get; set; }

}

而我的Models / EmployeeContext.cs只包含一个元素:

using System.Data.Entity;

.

.

.

public class EmployeeContext : DbContext {

public DbSet Employees { get; set; }

}

在Global.asax.cs文件中,我初始化了EmployeeContext模型的数据库:

protected void Application_Start() { //executed at the very beginning

Database.SetInitializer(null); //null -> no initialization strategy

AreaRegistration.RegisterAllAreas();

FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

RouteConfig.RegisterRoutes(RouteTable.Routes);

BundleConfig.RegisterBundles(BundleTable.Bundles);

}

如果表不存在,我还会得到什么错误?这可能会出错?有什么建议如何调试这种情况?

编辑:

当我评估employeeContext.Employees时,我得到以下值:

{SELECT

"Extent1"."Id" AS "Id",

"Extent1"."Name" AS "Name",

"Extent1"."Gender" AS "Gender",

"Extent1"."DateOfBirth" AS "DateOfBirth",

"Extent1"."EmployeeType" AS "EmployeeType",

"Extent1"."AnnualSalary" AS "AnnualSalary",

"Extent1"."HourlyPay" AS "HourlyPay",

"Extent1"."HoursWorked" AS "HoursWorked",

"Extent1"."City" AS "City"

FROM "dbo"."TBLEMPLOYEE" "Extent1"}

编辑2:

使用:

employeeContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

我在Debug输出窗口中得到以下内容:

SELECT

"Extent1"."Id" AS "Id",

"Extent1"."Name" AS "Name",

"Extent1"."Gender" AS "Gender",

"Extent1"."DateOfBirth" AS "DateOfBirth",

"Extent1"."EmployeeType" AS "EmployeeType",

"Extent1"."AnnualSalary" AS "AnnualSalary",

"Extent1"."HourlyPay" AS "HourlyPay",

"Extent1"."HoursWorked" AS "HoursWorked",

"Extent1"."City" AS "City"

FROM "dbo"."TBLEMPLOYEE" "Extent1"

WHERE ("Extent1"."Id" = :p__linq__0) AND (ROWNUM <= (2) )

编辑3:

这就是我的连接字符串的样子,以防万一需要它

providerName="System.Data.SqlClient" />

providerName="Oracle.ManagedDataAccess.Client"/>

entityFramework的设置如下:

问题可能是什么线索?

附加信息:

异常堆栈跟踪:

e.StackTrace

at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)

at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.b__6()

at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)

at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.b__5()

at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)

at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

at System.Data.Entity.Core.Objects.ObjectQuery`1..GetEnumerator>b__0()

at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()

at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)

at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.b__3[TResult](IEnumerable`1 sequence)

at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)

at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)

at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)

at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)

at MvcWebApplication1.Controllers.EmployeeController.Details(Int32 id) in c:\myapp\Controllers\EmployeeController.cs:line 25

内部异常堆栈跟踪:

(e.InnerException).StackTrace

at OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)

at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, Boolean isDescribeOnly, Boolean isFromEF)

at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)

at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.b__c(DbCommand t, DbCommandInterceptionContext`1 c)

at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)

at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)

at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值