Simple DataPortal_Fetch() Question

Simple DataPortal_Fetch() Question

Old forum URL: forums.lhotka.net/forums/t/8316.aspx


NickTaylor posted on Friday, January 08, 2010

Hi,

I'm sure there is a really simple answer to this, but I could do with some best practice advice on the following please...

I have a simple business object based on BusinessBase. Let's assume, to keep things easy, that its associated with a Customer, and is called BoCustomer. Ideally I want to be able to fetch a customer based on two parameters, firstly by its integer id, or secondly, by its string customer reference.

So, I have two public methods in my business object, the first being BoCustomer.GetByCustomerID(int customerID), and the second being BoCustomer.GetByCustomerReference(string customerReference).

Both use the SingleCriteria class to pass the appropriate reference parameter to the DataPortal_Fetch() method of the BO.

Given that I call a different stored procedure depending on whether I am getting a customer by its id or by its reference, and I am dealing with data of different types, I have assumed that two data portal fetch methods is the right approach. One requires a SingleCriteria<BoCustomer, int> parameter, and the other a  SingleCriteria<BoCustomer, string> . One calls the stored procedure to fetch a customer by its ID, and the other calls the stored procedure to fetch a customer by its reference.

Is this the right way to go, or is there a better way to do it...?

Thanks,

Nick

RockfordLhotka replied on Friday, January 08, 2010

That's how I would do it. Hopefully with a third, private, method that I can pass the open datareader (or whatever) so it can load the object's property values consistently regardless of the sproc you called.

NickTaylor replied on Friday, January 08, 2010

Many thanks for that Rocky, I just wanted to be sure I was heading down the right road.

And yes, I would have a common Load(SqlDataReader dr) method that loads the BO properties irrespective of which method was originally called to query the DB.

Many thanks for your response,

Nick

Copyright (c) Marimer LLC