Hello , i have a simple model
Config and MyValue
public Class Config
Public Property ConfigId as Integer
Public Property Name As String
Public Property MyValue as MyValue
Public Property ...
end class
Public Class MyValue
Public Property MyValueId as Integer
Public Property Value as Decimal
Public Property Info As String
Public Property ...
end class
I want to update my Config in database after changing:
- Name Text in TextBox (binding ViewModel)
- MyValue object in ComboBox (binding ViewModel)
- other values with binding
Public Function SaveExececute() As String
ObjConfig.Name = StrName
ObjConfig.MyValue = ObjValue
Using ctx As New DbContext
Try
ctx.Entry(ObjConfig).State = Entity.EntityState.Modified
ctx.SaveChanges()
Return "UPDATED"
Catch ex As Exception
Return ex.Message
End Try
End Using
End Sub
What I have tried:
all the values as been modified on database except my new MyValue ID 2 (MyValue_MyValueId = 1), the Disconnect Method do not recognize the new object MyValue, how to Attach and update the new Object MyValue ?
i Try to add this code but not working
Using ctx As New LgmModel
Try
ctx.Entry(ObjConfig.MyValue).State = Entity.EntityState.Modified
ctx.Entry(ObjConfig).State = Entity.EntityState.Modified
ctx.SaveChanges()
Return "UPDATED"
Catch ex As Exception
Return ex.Message
End Try
End Using