c# - How can I update object that contains other objects in lists with npoco? -
c# - How can I update object that contains other objects in lists with npoco? -
i have class properties list other class objects within it.
[tablename("tblitem")] [primarykey("itm_id", autoincrement = false)] [explicitcolumns] public class item { [column("itm_id")] public guid id { get; set; } [column("itm_name")] public string name { get; set; } public list<picturelink> picturelink { get; set; } } [tablename("tblpicturelink")] [primarykey("pil_id", autoincrement = false)] [explicitcolumns] public class picturelink { [column("pil_id")] public guid id { get; set; } [column("pil_informationtype")] public string informationtype { get; set; } }
i want create update npoco db.update(item) - properties id , name gets updated, how can create list picturelinks update in same statement?
enclose update kid objects in loop follows:
using (var scope = db.gettransaction()) { db.update(item); foreach (var picturelink in item.picturelinks) { db.update(picturelink); } scope.complete(); }
enclosing update in transaction ensure rollback if goes wrong.
c# .net npoco
Comments
Post a Comment