ODP.NET with Entity Framework: Problem with Guid
862109May 16 2011 — edited Jun 15 2011Hello,
in our database most of the keys are Guid's.
For example:
TBOBJECT
COOBJECTID (Guid) Key,
COTYPEID (Int32),
...
In the following little test program I tried to retrieve data from the table above (we use Visual Studio 2010, EF4 and ODAC 1120230 Beta):
using System;
using System.Data.Objects;
using System.Diagnostics;
using System.Linq;
namespace Otto
{
class Program
{
static void Main()
{
try
{
using (var entities = new Isgus())
{
var objectParameter1 = new ObjectParameter("P1", 100004);
var objectQuery1 = entities.TBOBJECT.Where("it.COTYPEID = @P1", objectParameter1);
var result1 = objectQuery1.Execute(MergeOption.NoTracking);
var objectToLoad1 = result1.FirstOrDefault();
var objectParameter2 = new ObjectParameter("P1", new Guid("264b765c-b257-4e63-ab18-4775fb99afc1"));
var objectQuery2 = entities.TBOBJECT.Where("it.COOBJECTID = @P1", objectParameter2);
var result2 = objectQuery2.Execute(MergeOption.NoTracking);
var objectToLoad2 = result2.FirstOrDefault();
}
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
}
}
First access with COTYPEID works.
The second access with Guid (Oracle raw(16)) throws an exception:
A first chance exception of type 'System.Data.EntityCommandExecutionException' occurred in System.Data.Entity.dll
An error occurred while executing the command definition. See the inner exception for details.
System.ArgumentException: Ungültiges Parameter-Binding
Parameter name: P1
at Oracle.DataAccess.Client.OracleParameter.GetBindingSize_Raw(Int32 idx)
at Oracle.DataAccess.Client.OracleParameter.PreBind_Raw()
at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
The thread '<No Name>' (0x69c) has exited with code 0 (0x0).
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
at Otto.Program.Main() in D:\Projects\Zeus4\Testprograms\Otto\Program.cs:line 25
I have no idea what is wrong.
Thanks in advance
Best regards Peter
Edited by: user13160192 on 16.05.2011 00:40
Edited by: user13160192 on 16.05.2011 00:50
Edited by: user13160192 on 16.05.2011 03:40