The following code is for mapping a dataRecord to a class. I don't like this solution since it requires to duplicate the logic of mapping for each field in every method which access to the same table.
What do you think about? What about using automapper?
public IEnumerable<Model.Accounts.User> GetUsers(int IDUser)
{
using (var sqlClient = CreateSqlManagerInstance("ListUser", CommandType.StoredProcedure))
{
sqlClient.AddParameterWithValue("IDUser", IDUser);
return sqlClient.ExecuteResultSet().Select(
dataRecord => new GModel.Accounts.User
{
IDUser = dataRecord.GetInt("IdUtente"),
FirstName = dataRecord.GetString("Nome"),
LastName = dataRecord.GetString("Cognome"),
//[...]
}).ToArray();
}
}
Avoiding code duplication in mapping layer between dataRecord and
and what ? – Marc-Andre Mar 14 '14 at 16:53