asp.net - How to change the ID of a complex type property in entity framework without first selecting the object? -
if have object property of complex type object b, how can change a.b b object without first selecting new b object?
for example, know can this
a.b = (from b in db.bs b.id = newid select b).first()
but rather this
a.b.id = newid
and assume can't because overwrite properties of existing b object empty values
b = new b { .id = newid } db.bs.attach(b) a.b = b
you have a.b
property call constructor on demand when b
not yet initialized.
i converted c# vb.net without testing it, same pattern works everywhere. make sure initialize property nothing
or null
first, , in property accessor call constructor if private member variable not initialized. return value usual.
public class b public property id() [string] return m_id end set m_id = value end set end property private m_id [string] end class public class private _b b public sub new() _b = nothing end sub public property b() b if _b nothing _b = new b() end if return _b end set _b = value end set end property end class
and can set properties on a.b impunity!
dim new a() a.b.id = "b created on demand!"
Comments
Post a Comment