本文介绍了实体框架 - 一对一关系,如何保存记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试保存一个新的记录,困惑如何保存到第二个实体。我尝试了以下内容。
将myObject作为新的MyObject
myObject.prop1 = 5
myObject.prop2 =Test
myObject.myOtherObject.prop1 = 3
myObject.myOtherObject.prop2 =Hello
但是当我点击 myObject.myOtherObject.prop1 = 3
时会收到错误,因为 myOtherObject
尚未初始化。
如何在 myObject
之前初始化子对象?
解决方案
尝试:
将myObject作为新的MyObject
myObject.prop1 = 5
myObject.prop2 =Test
myObject.myOtherObject = new MyOtherObject
myObject.myOtherObject.prop1 = 3
myObject.myOtherObject .prop2 =你好
I have a one-to-one relationship on two tables with are represented by 2 classes in my EDM.
I am trying to save a new record and am confused how to save to the second entity. I have tried the following.
Dim myObject as new MyObject
myObject.prop1 = 5
myObject.prop2 = "Test"
myObject.myOtherObject.prop1 = 3
myObject.myOtherObject.prop2 = "Hello"
But I get an error when I hit myObject.myOtherObject.prop1 = 3
because myOtherObject
hasn't been initialized.
How do I initialize an child object under myObject
?
解决方案
Try:
Dim myObject as new MyObject
myObject.prop1 = 5
myObject.prop2 = "Test"
myObject.myOtherObject = new MyOtherObject
myObject.myOtherObject.prop1 = 3
myObject.myOtherObject.prop2 = "Hello"
这篇关于实体框架 - 一对一关系,如何保存记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!