Avoiding code duplication in mapping layer between dataRecord and 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&lt;Model.Accounts.User&gt; GetUsers(int IDUser)
{
    using (var sqlClient = CreateSqlManagerInstance("ListUser", CommandType.StoredProcedure))
    {
        sqlClient.AddParameterWithValue("IDUser", IDUser);
        return sqlClient.ExecuteResultSet().Select(
           dataRecord =&gt; new GModel.Accounts.User
           {
               IDUser = dataRecord.GetInt("IdUtente"),
               FirstName = dataRecord.GetString("Nome"),
               LastName = dataRecord.GetString("Cognome"),
               //[...]
           }).ToArray();
    }
}
I believe the easiest way to avoid duplication each time you read from the database is to create a constructor which receives a DataRecord as a parameter, and does the heavy lifting:

public class User {

    public User() {}

    public User(DataRecord dataRecord) {
        IDUser = dataRecord.GetInt("IdUtente");
        FirstName = dataRecord.GetString("Nome");
        LastName = dataRecord.GetString("Cognome");
        //[...]
    }

    //...
}


And then:

public IEnumerable&lt;Model.Accounts.User&gt; GetUsers(int IDUser)
{
    using (var sqlClient = CreateSqlManagerInstance("ListUser", CommandType.StoredProcedure))
    {
        sqlClient.AddParameterWithValue("IDUser", IDUser);
        return sqlClient.ExecuteResultSet().Select(
           dataRecord =&gt; new GModel.Accounts.User(dataRecord)).ToArray();
    }
}




You could also use an automatic mapping library, but before you choose to do that, you might  want to look at some O/R mapping library, like NHibernate for c#, which should replace the mapping in your code altogether.