I had a code working on a localdb SQL Server DataBase, using Entity Framework 6 and DataBase first aproach. One of the tasks of this code is to insert values into a master-detail tables. Now I have to migrate the solution into MySQL, and I getting a DbUpdateException wich I know is caused by the detail table.
I've got this Entity classes:
Partial Public Class GSPC_Resultado
Public Property ResultadoID As Long
Public Property Fecha As Date
Public Property ConfiguracionID As Long
Public Overridable Property GSPC_Configuracion As GSPC_Configuracion
Public Overridable Property GSPC_ResultadoDetalle As ICollection(Of GSPC_ResultadoDetalle) = New HashSet(Of GSPC_ResultadoDetalle)
End Class
Partial Public Class GSPC_ResultadoDetalle
Public Property ResultadoDetalleID As Long
Public Property ResultadoID As Long
Public Property RutaID As Long
Public Property NombreArchivo As String
Public Property AccionCompletada As Nullable(Of SByte)
Public Overridable Property GSPC_Resultado As GSPC_Resultado
Public Overridable Property GSPC_ResultadoRuta As GSPC_ResultadoRuta
End Class
Let's say I have a code to insert master-detail like that (simplified):
Dim resultado As New GSPC_Resultado
resultado.ConfiguracionID = 1
resultado.Fecha = DateTime.Now
Dim resultadoDetalle As New GSPC_ResultadoDetalle
resultadoDetalle.RutaID = 1
resultadoDetalle.NombreArchivo = "myname"
resultadoDetalle.AccionCompletada = True
resultado.GSPC_ResultadoDetalle.Add(resultadoDetalle)
context.GSPC_ResultadoSet.Add(resultado)
context.SaveChanges()
Trying to catch the exception to find the issue:
Try
context.SaveChanges()
Catch ex As DbUpdateException
For Each entry As DbEntityEntry In ex.Entries
Console.WriteLine("Type {0} ", entry.Entity.GetType().Name)
Next
End Try
With this I know that the entity GSPC_ResultadoDetalle is causing the exceptyion, but I do not see wich field is causing this exception. Some exception properties are:
- Message: "An error occurred while updating the entries. See the InnerException for details."
- InnerException: The specified value is not an instance of a valid constant type.
As I said, this worked on a SQL Server (localdb), but not on MySQL. Unfortunately I'm not able to identify with field of GSPC_ResultadodDetalle is causing the exception, but I suspect that GSPC_ResultadoDetalle is unable to get the ResultadoID value from GSPC_Resultado.
Any suggestions?
Thank's in advice,
Ferran.