Castle ActiveRecord lazy/proxy issues

40 views
Skip to first unread message

Tim Schmidt

unread,
Apr 4, 2012, 4:18:37 PM4/4/12
to castle-pro...@googlegroups.com
I have an ActiveRecord class, let's call it MyClass, that's set Lazy=true at the class level.  When I call ActiveRecordMediator<MyClass>.FindByPrimaryKey(0), I get back a MyClass proxy object (since id 0 doesn't exist).  I guess I would expect to get a null but I can see why I get a proxy.  My question is how the heck do I check if that record actually existed?  Right now, as soon as I access any property on the returned proxy object, I get an ObjectNotFoundException.

Help!

tim

Tim Schmidt

unread,
Apr 4, 2012, 4:23:09 PM4/4/12
to castle-pro...@googlegroups.com
Follow up question, in this case I don't really even care to lazy load.  Can I bypass that behavior for this one call?

Alessandro Cavalieri

unread,
Apr 12, 2012, 11:38:32 AM4/12/12
to castle-pro...@googlegroups.com
If I remember well FindByprimaryKey has an overload:
public static object FindByPrimaryKey(Type targetType, object id, bool throwOnNotFound);

with the overload you can specify the action when the record doesn't exist.

ciao
Alessandro 
Reply all
Reply to author
Forward
0 new messages