Entity Framework, Guid and insert exception

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
robymes
Posts: 29
Joined: Tue 09 Sep 2008 09:46

Entity Framework, Guid and insert exception

Post by robymes » Fri 03 Oct 2008 09:39

Hello,
I installed the latest OraDirect version (4.75.43).
It works very well with System.Guid mapped on RAW(16) columns when reading from DB, but it throws an Exception when inserting a new record.
Here's the client code, Customer is a class (and table on db) with a Guid Id and a string Name (RAW(16) and NVARCHAR(100) on db)

Code: Select all

using (TestOracleDtcDataContext context = new TestOracleDtcDataContext())
            {
                Customer customer = Customer.CreateCustomer(Guid.NewGuid(), "David");
                context.AddToCustomerSet(customer);                
                context.SaveChanges();
            }
Here's the error

TestOracleDtc.DomainModel.Test.TestOracleDtcDataContextTestCase.Insert threw exception: System.Data.UpdateException
System.Data.EntityCommandCompilationException: System.NotSupportedException

Here's the stack

CoreLab.Oracle.OracleUtils.a(DbType A_0)
CoreLab.Oracle.OracleParameter.set_DbType(DbType value)
CoreLab.Common.Entity.h.a.a(Object A_0, TypeUsage A_1)
CoreLab.Common.Entity.h.a.a(DbConstantExpression A_0)
CoreLab.Oracle.Entity.c.a.a(DbConstantExpression A_0)
System.Data.Common.CommandTrees.DbConstantExpression.Accept(DbExpressionVisitor visitor)
CoreLab.Common.Entity.h.a(DbInsertCommandTree A_0, DbCommand A_1, DbProviderManifest A_2)
CoreLab.Oracle.Entity.a.a(DbCommandTree A_0, DbConnection A_1, DbProviderManifest A_2)
CoreLab.Oracle.Entity.OracleEntityProviderServices.a(DbProviderManifest A_0, DbCommandTree A_1)
CoreLab.Oracle.Entity.OracleEntityProviderServices.b(DbProviderManifest A_0, DbCommandTree A_1)
System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
System.Data.Objects.ObjectContext.SaveChanges()
TestOracleDtc.DomainModel.Test.TestOracleDtcDataContextTestCase.Insert() in D:\Users\roberto\Documenti\Dev\VisualStudio\2008\TestOracleDtc\TestOracleDtc.DomainModel.Test\TestOracleDtcDataContextTestCase.cs: line 88

same thing if i try to update an entity.
My doubt is that you are not supporting insert and update with Guids...

robymes
Posts: 29
Joined: Tue 09 Sep 2008 09:46

Post by robymes » Fri 03 Oct 2008 13:26

following the exception stack and analyzing your code with Reflector i think the issue is here (from CoreLab.Oracle.OracleUtils):

Code: Select all

internal static OracleDbType a(DbType A_0)
{
    switch (A_0)
    {
        case DbType.AnsiString:
        case DbType.String:
            return OracleDbType.VarChar;

        case DbType.Binary:
            return OracleDbType.Blob;

        case DbType.Byte:
        case DbType.Int16:
        case DbType.Int32:
        case DbType.SByte:
        case DbType.UInt16:
            return OracleDbType.Integer;

        case DbType.Boolean:
            return OracleDbType.Boolean;

        case DbType.Currency:
        case DbType.Decimal:
        case DbType.Int64:
        case DbType.UInt64:
        case DbType.VarNumeric:
            return OracleDbType.Number;

        case DbType.Date:
            return OracleDbType.Date;

        case DbType.DateTime:
            return OracleDbType.TimeStamp;

        case DbType.Double:
            return OracleDbType.Double;

        case DbType.Object:
            return OracleDbType.Object;

        case DbType.Single:
            return OracleDbType.Float;

        case DbType.Time:
            return OracleDbType.IntervalDS;

        case DbType.AnsiStringFixedLength:
        case DbType.StringFixedLength:
            return OracleDbType.Char;
    }
    throw new NotSupportedException();
}
here I think the following statement is missing:

Code: Select all

case DbType.Guid:
return OracleDbType.Raw;
without this piece of code try to set a Guid parameter will throw the final NotSupportedException.
Am I right?

Shalex
Devart Team
Posts: 8036
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 03 Oct 2008 13:32

The issue with EF and OraDirect .NET interoperation, when saving GUID, is confirmed. It is fixed already. The new build will be available next week.

robymes
Posts: 29
Joined: Tue 09 Sep 2008 09:46

Post by robymes » Fri 03 Oct 2008 13:45

Thanks for your support

Varun
Posts: 6
Joined: Thu 13 Nov 2008 15:14

Saving GUID declared as RAW in stored procedure

Post by Varun » Thu 13 Nov 2008 16:45

Is this fixed for OraDirect.NET 5 Beta release

I am getting the error

Error 2042: Parameter Mapping specified is not valid. The type 'Edm.Guid' of member 'ID' in type 'Model.TESTTABLE' is not compatible with 'Devart.Data.Oracle.RAW' of parameter 'PI_ID' in function 'Model.Store.TESTTABLE_PKG_UPDATETEST'.

Shalex
Devart Team
Posts: 8036
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 14 Nov 2008 10:31

The "RAW" type of the corresponding stored procedure parameter should be changed to "guid".

Varun
Posts: 6
Joined: Thu 13 Nov 2008 15:14

Post by Varun » Fri 14 Nov 2008 18:17

Could you give a little more explanation on how and where to do this change from RAW to guid

Varun
Posts: 6
Joined: Thu 13 Nov 2008 15:14

Post by Varun » Fri 14 Nov 2008 20:20

Thanks much found out how to do it.

Open Model in xml editor, change the Type="RAW" to Type="guid" for the stored procedure input param. For function imports change the Type Binary to Guid and off you go, it all works.

If this is not the way to do it, please post back the correct procedure, otherwise thanks much for the support, really appreciated.

Shalex
Devart Team
Posts: 8036
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 19 Nov 2008 12:55

Yes, you made right correction.

Post Reply