【发布时间】:2015-08-14 15:40:43
【问题描述】:
我正在使用 npgsql.entityframework,由于 XmlSerializer 实现的某些方面,我想要自定义处理映射。
我希望孩子使用 parent_id(只要)映射,而不是标准方法将子映射到父(作为父)。
我想在模型中保留向父级添加子级的功能,但我希望能够在不加载父级的情况下处理子级。
vb.net 中的代码(答案是 c# 或 vb)
示例父添加: 暗淡 p 作为新的父母 p.child.add(新孩子)
示例子添加未加载父,但父 ID 已知, 昏暗的c作为新的孩子 c.parent_id=known_parent_id
非常感谢任何帮助。
公共班级家长
Private m_childs As ICollection(Of Child)
<Runtime.Serialization.DataMember(), ComponentModel.DataAnnotations.Key>
Public Property id As Long
Public Overridable Property childs() As ICollection(Of child)
Get
Return m_childs
End Get
Set(value As ICollection(Of child))
m_childs = value
End Set
End Property
结束类
公共班级孩子
<Runtime.Serialization.DataMember(), ComponentModel.DataAnnotations.Key>
Public Property id As Long
Public Property parent As parent ' works but not desired
Public Property parent_id As Long' want to use this
结束类
/约翰
【问题讨论】:
标签: c# vb.net entity-framework entity-framework-6