/// <summary> /// Retrieves data from database using specified key value and fill to model /// </summary> /// <param name="key"> /// primary key value of record to be retrieved. /// </param> /// <returns> /// A GlobalTranz.Framework.Common.Models.IModel object /// </returns> public IModel SelectWithLock(object key) { SqlDataReader dataReader = null; SqlCommand command = new SqlCommand(); string selectWithLockSql = this.commandBuilder.GetSelectWithLockSql(); command.CommandText = selectWithLockSql; SqlParameter p = new SqlParameter(); p.ParameterName = "@key"; p.Value = key; command.Parameters.Add(p); command.Connection = (SqlConnection)this.connection; command.Transaction = (SqlTransaction)this.transaction; dataReader = command.ExecuteReader(); try { while (dataReader.Read()) { DataReaderConverter converter = new DataReaderConverter(this.modelType); return(converter.ConvertDataReaderToModel(dataReader)); } } finally { dataReader.Close(); } return(null); }
/// <summary> /// Generates select command from model and execute that stored procedure /// </summary> /// <param name="model"> /// Model object with parameter values. /// </param> /// <returns> /// Imodel object /// </returns> public IModel SelectProcedure(IModel model) { SqlDataReader dataReader = null; // creates new as command object using stored procedure SqlCommand command = this.commandBuilder.GetSelectCommand(model); command.Transaction = (SqlTransaction)this.transaction; command.Connection = (SqlConnection)this.connection; // executes select stored procedure dataReader = command.ExecuteReader(); try { while (dataReader.Read()) { DataReaderConverter converter = new DataReaderConverter(this.modelType); return(converter.ConvertDataReaderToModel(dataReader)); } } finally { dataReader.Close(); } return(null); }
/// <summary> /// Retrieves data from database using specified key value and fill to model /// </summary> /// <param name="key"> /// primary key value of record to be retrieved. /// </param> /// <returns> /// A GlobalTranz.Framework.Common.Models.IModel object /// </returns> public IModel Select(object key) { SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; command.Transaction = (SqlTransaction)this.transaction; command.Connection = (SqlConnection)this.connection; // create select statement and assign to the command object command.CommandText = this.commandBuilder.GetSelectSql(); // create a parameter for primary key. SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@key"; parameter.Value = key; command.Parameters.Add(parameter); SqlDataReader dataReader = command.ExecuteReader(); try { while (dataReader.Read()) { DataReaderConverter converter = new DataReaderConverter(this.modelType); return(converter.ConvertDataReaderToModel(dataReader)); } } finally { dataReader.Close(); } return(null); }