armen.shimoon
armen.shimoon

Reputation: 6401

EF using Oracle (ODP.NET) works on one machine, throwing exceptions on another

Everything works fine on my development box (Windows 7 64 bit), I am able to retrieve records and save records.

When I deploy out to a Windows Server 2008 (32 bit) machine, I am able to retrieve data and view it fine. The problem comes when I either:

1) Try to save:

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.ArgumentException: The specified value is not an instance of type 'Edm.Decimal'
Parameter name: value
   at System.Data.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.ValidateConstant(TypeUsage constantType, Object value)
   at System.Data.Mapping.Update.Internal.UpdateCompiler.GenerateValueExpression(EdmProperty property, PropagatorResult value)
   at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildPredicate(DbExpressionBinding target, PropagatorResult referenceRow, PropagatorResult current, TableChangeProcessor processor, Boolean& rowMustBeTouched)
   at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildUpdateCommand(PropagatorResult oldRow, PropagatorResult newRow, TableChangeProcessor processor)
   at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
   --- End of inner exception stack trace ---
   at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
   at System.Data.Mapping.Update.Internal.UpdateTranslator.<ProduceDynamicCommands>d__0.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Data.Mapping.Update.Internal.UpdateCommandOrderer..ctor(IEnumerable`1 commands, UpdateTranslator translator)
   at System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
   at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
   at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
   at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at Dashboard.Data.Repository.RepositoryBase`2.OnCompleteSave()

2) Or try to retrieve the next number in a sequence:

System.InvalidOperationException: The specified cast from a materialized 'System.Decimal' type to the 'System.Int64' type is not valid.
   at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
   at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at Dashboard.Data.DashboardDbContext.ExecuteScalar[TResult](String query, Object[] parameters) in c:\Builds\1\Exploration Archives\Dashboard (MAIN) (talus test)\Sources\Exploration Archives\Dashboard\Main\Dashboard.Data\Dashboard.contrib.cs:line 23
   at Dashboard.Data.Repository.RepositoryBase`2.GetNextIdFromSequence()

The part that confuses me the most is the fact that after being deployed to the Windows Server 2008 machine, things partially work (I am able to retrieve data), but it only breaks when I try to retrieve from a sequence or save.

Any ideas what could be causing this?

Upvotes: 1

Views: 1637

Answers (2)

Sam Sippe
Sam Sippe

Reputation: 3190

Adding a comment here for future reference as this issue also effects the Mysql Drivers - EntityFramework v6 and MySql.Data.Entities.6.8.3.0. Unsigned bigint db columns cause this issue.

"id BIGINT(20) UNSIGNED" causes a "The specified value is not an instance of a valid constant type. Parameter name: type" exception. Changing the associated class property ulong does not help. Binding db column "id BIGINT(20)" to...

[Key]
[Column("id")]
public long Id { get; set; }

...works fine.

Upvotes: 0

armen.shimoon
armen.shimoon

Reputation: 6401

Found the issue.

For my ID columns, on my .NET objects I was using data type long, with the corresponding oracle data type number. Worked fine on my machine. Based on other research into this issue, I tried changing the oracle data type to number(19). Still no go.

Seems like long support is flaky at best. I had to change my .NET objects' data types to int, and changed the oracle data types to int as well. This worked.

The part that bothers me most is that it obviously saw number and number(19) as a decimal data type, and it had no problem doing a narrowing conversion for me to long. The issue only came up when I tried to save, doing a non-narrowing conversion long to decimal. Go figure.

Upvotes: 2

Related Questions