我有一个简单的模型配置和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
我想在更改后更新数据库中的配置:- TextBox中的名称文本(binding ViewModel) - ComboBox中的MyValue对象(binding ViewModel) -具有绑定的其他值
Public Function SaveExececute() As String
ObjConfig.Name = SomeString 'FAKE All is binded'
ObjConfig.MyValue = SomeObject 'FAKE All is binded'
' ... '
Using ctx As New DbContext
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
End Sub
除了我的Id为2的新MyValue (我的sql数据库上的MyValue_MyValueId=1),Disconnect方法无法识别新对象MyValue之外,所有在数据库上修改的值,如何附加和更新新对象MyValue?
https://stackoverflow.com/questions/44450410
复制相似问题