c# - Trying to deal with nHibernate proxy classes due to inheritance -
i have table-per-hierarchy setup (below domain objects). problem when dealing of returned nhibernate objects, proxy's of base type.
i found answer(as few others), 1 gave link article not losing lazy-loading.
problem
however, after attempting articles suggestion of placing generic method on base class returns type of type argument, new error
error: "late bound operations cannot performed on types or methods containsgenericparameters true."
note: understand can turn off lazy loading in mappings, mentioned earlier, trying take advantage of not losing lazy loading.
nhibernate version: 3.3.1.4000 fluent nhibernate version: 1.3.0.733
public class itembase : iitembase { public virtual int id { get; set; } public virtual int version { get; set; } public virtual string name { get; set; } public virtual string description { get; set; } public virtual t as<t>() t : itembase { return t; } //removed brevity } public class item : itembase { public virtual store store { get; set; } } public class vendoritem : itembase { public virtual vendor vendor { get; set; } }
what missing resolve issue?
update
to add problem, if use nhibernate "unproxy" method session:
nhsession.getsessionimplementation().persistencecontext.unproxy
this works if within same session. however, in 1 case attempting access outside original session , error: object uninitialized proxy
the answer required using visitor pattern. nhibernate's return type proxy of base class, attempts cast desired type not possible. visitor pattern allows identify type of object after through polymorphism.
Comments
Post a Comment