简体   繁体   中英

Is a bad practice to use in method signature DbCommand?

I'm using the DbCommand from the EnterpriseLibrary. I have two methods which get same formated select from the database. So the DataReader looks same but, I'm executing other procedures.

My question is: is it a good idea is move to one method executing DbCommand and data reading from DataReader like this:

public Dictionary<Guid,List<string>> GetCurrentLoginData()
{
   // here is maked command and private method is called
}
public Dictionary<Guid,List<string>> GetSpecificLoginData(string login)
{
   // here is maked command and private method is called
}

// method which is called from both public methods
private Dictionary<Guid,List<string>> GetLoginData(DbCommand command)
{
   // here is code to executeCommand and data reading
}

Or maybe there is a better way? My other way is to move only the data reading to other method.

Thanks for answers, I hope this will help me.

I don't see anything bad with this approach. You are moving common functionality into the GetLoginData method, which is good practice, and the public methods have meaningful names and proper signatures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM