c# - How do I handle nested NPoco objects that may be null? -
i using npoco object mapping database. have following entities:
public abstract class namedentity { public int id { get; set; } public string name { get; set; } } public class person : namedentity { public office office { get; set; } } public class office : namedentity { public address address { get; set; } public organisation parentorganisation { get; set; } } public class address { public string addressline1 { get; set; } } public class organisation : namedentity { }
and retrieving objects using npoco in repository:
var people = context.fetch<person, office, address, organisation>(sql);
this working fine, except case person
not have office
, in case result of left join
in sql query returns null office, address , organisation columns.
in situation, unhandled exception thrown in npoco:
system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> system.nullreferenceexception: object reference not set instance of object. @ poco_automapper(person , office , address , organisation ) --- end of inner exception stack trace --- @ system.runtimemethodhandle.invokemethod(object target, object[] arguments, signature sig, boolean constructor) @ system.reflection.runtimemethodinfo.unsafeinvokeinternal(object obj, object[] parameters, object[] arguments) @ system.delegate.dynamicinvokeimpl(object[] args) @ npoco.multipocofactory.callcallback[tret](delegate callback, idatareader dr, int32 count) @ npoco.multipocofactory.<>c__displayclassa`1.<createmultipocofactory>b__9(idatareader reader, delegate arg3) @ npoco.database.<query>d__14`1.movenext()
is there way handle situation? or have resort flattened object, or separate database calls?
this has been fixed in npoco 2.2.40.
reporting it.
Comments
Post a Comment