/// <summary> /// Execute SQL-instruction. /// </summary> /// <param name="commandName">Stored procedure name</param> /// <param name="inputParameters">Stored procedure input parameters</param> /// <param name="outputParameters">Stored procedure output results</param> /// <param name="settings">Data mapping used to resolve entity property path</param> public virtual IEnumerable <T> Execute <T>(string commandName, InputCollection inputParameters, OutputCollection outputParameters, EntityMapperCollection specialMappers = null, DataReflectorCollection specialReflectors = null, DataAliasCollection settings = null, object bag = null) { try { // Specify output parameters if (outputParameters == null) { outputParameters = OutputCollection.Create(); } // Specify data map settings if (settings == null) { settings = new DataAliasCollection(); } // Aggregate reader collection var mappers = new EntityMapperCollection(_mappers); if (specialMappers != null) { mappers.AddRange(specialMappers); } // Aggregate reflector collection var reflectors = new DataReflectorCollection(_reflectors); if (specialReflectors != null) { reflectors.AddRange(specialReflectors); } // Evaluate mappings collection EntityMappingCollection mappings = mappers.TakeMappings(); // Using db-command using (var command = Connection.CreateCommand()) { // Setup command command.CommandText = commandName; command.CommandType = CommandType.StoredProcedure; // Add parameters in input collection foreach (var parameter in inputParameters) { command.AddParameter(parameter); } // Execute query/non query return(ExecuteQuery <T>(command, outputParameters.ToArray(), settings, mappings, mappers, reflectors, bag)); } } catch (DataLayerException) { throw; } catch (Exception ex) { throw new DataLayerException(Properties.Resources.DataLayerExceptionMessage, ex); } }
/// <summary> /// Register EntityReflector for reading entity of T1 type to global EntityAccessor scope /// </summary> /// <param name="collection"></param> protected void UsingReflectors(DataReflectorCollection collection) { _reflectors.AddRange(collection); }