我有一个.Net应用程序链接到具有这样的用户定义类型的Oracle数据库:
create or replace TYPE Person as object (firstname varchar2(50),lastname varchar2(50));
UDT在应用程序级别具有以下对象:
<OracleCustomTypeMapping("SCHEMA.PERSON")>
Public Class Person
Implements IOracleCustomType
Implements IOracleCustomTypeFactory
Implements INullable
Private FirstName_ As String
<OracleObjectMapping("FIRSTNAME")>
Public Property FirstName As String
Get
Return FirstName_
End Get
Set(value As String)
FirstName_ = value
IsNull_ = False
End Set
End Property
Private LastName_ As String
<OracleObjectMapping("LASTNAME")>
Public Property LastName As String
Get
Return LastName_
End Get
Set(value As String)
LastName_ = value
IsNull_ = False
End Set
End Property
Public Sub New()
IsNull_ = True
End Sub
Public Sub FromCustomObject(Connection As OracleConnection, Pointer As IntPtr) Implements IOracleCustomType.FromCustomObject
OracleUdt.SetValue(Connection, Pointer, "FIRSTNAME", FirstName)
OracleUdt.SetValue(Connection, Pointer, "LASTNAME", LastName)
End Sub
Public Sub ToCustomObject(Connection As OracleConnection, Pointer As IntPtr) Implements IOracleCustomType.ToCustomObject
FirstName = CStr(OracleUdt.GetValue(Connection, Pointer, "FIRSTNAME"))
LastName = CStr(OracleUdt.GetValue(Connection, Pointer, "LASTNAME"))
IsNull_ = False
End Sub
Public Function CreateObject() As IOracleCustomType Implements IOracleCustomTypeFactory.CreateObject
Return New Person
End Function
Public ReadOnly Property IsNull As Boolean Implements INullable.IsNull
Get
Return IsNull_
End Get
End Property
Private IsNull_ As Boolean = True
End Class
应用程序对象与数据库对象之间的通信运行良好。我可以从数据库加载数据,但是当尝试将数据保存回数据库时,出现错误:没有为此对象定义无参数构造函数。我不知道此错误的出处,因为我的对象确实具有无参数的构造函数。
我尝试使用DataAdapter将数据返回保存到数据库中。
'Load data from database
Command = New OracleCommand("Select * from MyTable", Connection)
Command.CommandType = CommandType.Text
DataAdapter = New OracleDataAdapter(Command)
DataAdapter.FillSchema(DataSet, SchemaType.Source, "MyTable")
DataAdapter.Fill(DataSet, "MyTable")
DataTable = DataSet.Tables("MyTable")
'Make some change
'Change some rows values
'...
'Save databack to the database
DataAdapter.Update(DataTable) '<<<< Where the error is raised
这是堆栈跟踪:
Stack trace:
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at Oracle.DataAccess.Client.OracleDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
有人知道如何解决吗?
谢谢,欢呼声