DataPortal_Fetch
Old forum URL: forums.lhotka.net/forums/t/5625.aspx
triviany posted on Sunday, October 19, 2008
Hi there,
Just joined and am loving the framework and community - thanks Rocky and community!
Pardon me if this question is silly:
This is my code:
Contact contact = Contact.GetContact(contactID);
GetContact() returns a Contact object given a contactID...pretty straightforward....so
my question is why does the DataPortal mechanism return an Contact object when the contact doesn't exist in the db?
If it's explained in the book then please point me in the right direction.
Many thanks
T
reagan123 replied on Sunday, October 19, 2008
Take a look at this thread.. I think it may talk about the same thing.
http://forums.lhotka.net/forums/thread/12301.aspx
Maybe someone with more info can come and explain here though. :)
triviany replied on Monday, October 20, 2008
Thanks reagan123. Will check out the link.
T
ajj3085 replied on Monday, October 20, 2008
Well usually if I don't get back a record because it doesn't exist in the database, I throw an exception. If you don't though, the DP call will return an object, although I'm not sure what state it will be in.. but that all depends on what you do. Csla doesn't force you how to handle this case, but an exception seems to be most appropriate, but your code could return null. I wouldn't recommend letting an actual object come back though to the client. That would be confusing.
triviany replied on Monday, October 20, 2008
Cheers. My biggest concern was that an object was being returned. However, after reading through replies in the link above, it makes more sense for me to catch the exception thrown by the DP and return null.
Thank you.
T
ajj3085 replied on Tuesday, October 21, 2008
Sounds good. Just to be clear though, it's up to your code in the DataPortal_Fetch to throw an exception; Csla doesn't do that for you.
triviany replied on Tuesday, October 21, 2008
Aha! I seem to notice the DP mechanism throwing some sort of an error between the call to DataPortal_Fetch and the return from the business method.
I better investigate this further. It's always worth knowing how the whole thing works.
Cheers mate!
T
Copyright (c) Marimer LLC