c# - DOT.NET System.Data.Entity.DbContext, mapping parent to child but not child to parent -
i'm using npgsql.entityframework , due aspects of implementation of xmlserializer want custom handling of mapping.
instead of standard method of mapping child parent (as parent) want child mapped using parent_id (as long).
i want keep function of adding child parent in model, want able handle child(s) without loading parent.
code in vb.net (answers c# or vb)
example parent add: dim p new parent p.child.add( new child )
example child add without parent loaded, parent id known, dim c new child c.parent_id= known_parent_id
any appreciated.
public class parent
private m_childs icollection(of child) <runtime.serialization.datamember(), componentmodel.dataannotations.key> public property id long public overridable property childs() icollection(of child) return m_childs end set(value icollection(of child)) m_childs = value end set end property
end class
public class child
<runtime.serialization.datamember(), componentmodel.dataannotations.key> public property id long public property parent parent ' works not desired public property parent_id long' want use
end class
/johan
found solution,using foreignkey in child mapping parent enabled use of both methods.
<system.componentmodel.dataannotations.schema.foreignkey("parent")> _ public property parent_id long <xml.serialization.xmlignore> _ public property parent parent
Comments
Post a Comment