0

I have a code like this, how I can do to set the "CommnadTimeout"?

var database = EnterpriseLibraryContainer.Current.GetInstance<Database>();
var sqlGetAllPersons = @"select * from Person.Person";
var personMapper = MapBuilder<Person>.MapAllProperties().Build();

// create an accessor (DataAccessor)
var personAccessor = database.CreateSqlStringAccessor<Person>(sqlGetAllPersons, personMapper);

// execute the accessor (IEnumerable<Person>)
var profiles = personAccessor.Execute();

(code from EntLib 5.0 DAAB MapBuilder maps DBNull to null)

thanks

andres descalzo
  • 14,887
  • 13
  • 64
  • 115

1 Answers1

1

Although I like little this solution, I was able to fix it this way:

public class ParameterMapperWithCommandTimeout : IParameterMapper
{
    public int CommandTimeout { get; set; }

    public void AssignParameters(DbCommand command, object[] parameterValues)
    {
        command.CommandTimeout = this.CommandTimeout;
    }
}

applied to the previous example:

var database = EnterpriseLibraryContainer.Current.GetInstance<Database>();
var sqlGetAllPersons = @"select * from Person.Person";
var personMapper = MapBuilder<Person>.MapAllProperties().Build();
var parameterMapper = new ParameterMapperWithCommandTimeout { CommandTimeout = MyTimeOut };

// create an accessor (DataAccessor)
var personAccessor = database.CreateSqlStringAccessor<Person>(sqlGetAllPersons, parameterMapper, personMapper);

// execute the accessor (IEnumerable<Person>)
var profiles = personAccessor.Execute();
andres descalzo
  • 14,887
  • 13
  • 64
  • 115
  • 1
    This is about the best you're going to get. Accessors are deliberately less than full featured, and don't allow a whole lot of customization. The point you plugged in is pretty much the only place the DbCommand is exposed. – Chris Tavares Nov 30 '12 at 00:28