0

我尝试使用 BlToolkit 将实体插入到 oracle 数据库中。与 System.Data.OracleClient 的连接。ms sql server 一切正常。但是,当我迁移到 oracle 时,insert for guid 给了我错误。选择完美地工作。有什么建议吗?

模型:

[TableName("TEST")]
public class Test
{
    [MapField("TEST_ID")]
    [PrimaryKey]
    public Guid TestId { get; set; }
    [DisplayName("Kodu")]
    [MapField("TEST_KODU")]
    public string TestKodu { get; set; }
    [DisplayName("Test Kısa Adı")]
    [MapField("TEST_KISA_ADI")]
    public string TestKisaAd { get; set; }
    [DisplayName("Test Adı")]
    [MapField("TEST_ADI")]
    public string TestAdi { get; set; }
    public Test()
    {
    }
    public Test(Guid _id, string _kod, string _adi, string _kisaAdi)
    {
        TestId = _id;
        TestKodu = _kod;
        TestKisaAd = _kisaAdi;
        TestAdi = _adi;
    }
}

数据库管理器:

public class DbProvider : DbManager
    {
        public DbProvider() : base("ElabConnectionString")
        {

        }    
    }

在行动:

var db = new DbProvider();
db.Insert(test);

给定错误:

Hata: BLToolkit.Data.DataException: Failed to convert parameter value from a Guid to a Byte[]. ---> System.InvalidCastException: Failed to convert parameter value from a Guid to a Byte[]. ---> System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Data.OracleClient.OracleParameter.CoerceValue(Object value, MetaType destinationType)
   --- End of inner exception stack trace ---
   at System.Data.OracleClient.OracleParameter.CoerceValue(Object value, MetaType destinationType)
   at System.Data.OracleClient.OracleParameter.SetCoercedValueInternal(Object value, MetaType metaType)
   at System.Data.OracleClient.OracleParameterBinding.PrepareForBind(OracleConnection connection, Int32& offset)
   at System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
   at BLToolkit.Data.DbManager.ExecuteOperation[T](OperationType operationType, Func`1 operation)
   --- End of inner exception stack trace ---
   at BLToolkit.Data.DbManager.OnOperationException(OperationType op, DataException ex)
   at BLToolkit.Data.DbManager.HandleOperationException(OperationType op, Exception ex)
   at BLToolkit.Data.DbManager.ExecuteOperation[T](OperationType operationType, Func`1 operation)
   at BLToolkit.Data.DbManager.ExecuteNonQueryInternal()
   at BLToolkit.Data.DbManager.ExecuteNonQuery()
   at BLToolkit.Data.DbManager.BLToolkit.Data.Linq.IDataContext.ExecuteNonQuery(Object query)
   at BLToolkit.Data.Linq.Query`1.NonQueryQuery(IDataContextInfo dataContextInfo, Expression expr, Object[] parameters)
   at BLToolkit.Data.Linq.Query`1.<SetNonQueryQuery>b__e(QueryContext ctx, IDataContextInfo db, Expression expr, Object[] ps)
   at BLToolkit.Data.Linq.Query`1.Insert(IDataContextInfo dataContextInfo, T obj)
   at BLToolkit.Data.Linq.Extensions.Insert[T](IDataContext dataContext, T obj)
4

2 回答 2

1

Oracle 中没有 Guid (UniqueIdentifier) 数据类型,您必须改为提供字节数组。在 Oracle 中,将 Guid 定义为 RAW(16),然后在 C# 程序中,使用 Guid.ToByteArray() 方法。

于 2013-01-28T09:27:47.793 回答