Beispiel #1
0
 /// <summary>
 /// Executes a Sql INSERT statement.
 /// Insert is a bit different from other update methods, as it
 /// provides facilities for returning the primary key of the
 /// newly inserted row (rather than the effected rows).  This
 /// functionality is of course optional.
 /// <p/>
 /// The parameter object is generally used to supply the input
 /// data for the INSERT values.
 /// </summary>
 /// <param name="statementId">The name of the statement to execute.</param>
 /// <param name="parameterObject">The parameter object.</param>
 /// <returns>
 /// The primary key of the newly inserted row.
 /// This might be automatically generated by the RDBMS,
 /// or selected from a sequence table or other source.
 /// </returns>
 public object Insert(string statementId, object parameterObject)
 {
     using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
     {
         IMappedStatement statement = GetMappedStatement(statementId);
         return(statement.ExecuteInsert(sessionScope.Session, parameterObject));
     }
 }
Beispiel #2
0
 /// <summary>
 /// Runs a query for list with a custom object that gets a chance to deal
 /// with each row as it is processed.
 /// <p/>
 /// The parameter object is generally used to supply the input
 /// data for the WHERE clause parameter(s) of the SELECT statement.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="statementId">The statement id.</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
 /// <param name="rowDelegate">The row delegate.</param>
 /// <returns>A List of result objects.</returns>
 public IList <T> QueryWithRowDelegate <T>(string statementId, object parameterObject, RowDelegate <T> rowDelegate)
 {
     using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
     {
         IMappedStatement statement = GetMappedStatement(statementId);
         return(statement.ExecuteQueryForRowDelegate(sessionScope.Session, parameterObject, rowDelegate));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Executes a Sql SELECT statement that returns a single object of the type of the
 /// resultObject parameter.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="statementId">The statement id.</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
 /// <param name="instanceObject">An object of the type to be returned.</param>
 /// <returns>
 /// The single result object populated with the result set data.
 /// </returns>
 public T QueryForObject <T>(string statementId, object parameterObject, T instanceObject)
 {
     using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
     {
         IMappedStatement statement = GetMappedStatement(statementId);
         return(statement.ExecuteQueryForObject(sessionScope.Session, parameterObject, instanceObject));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Runs a query with a custom object that gets a chance to deal
 /// with each row as it is processed.
 /// <p/>
 /// The parameter object is generally used to supply the input
 /// data for the WHERE clause parameter(s) of the SELECT statement.
 /// </summary>
 /// <typeparam name="K"></typeparam>
 /// <typeparam name="V"></typeparam>
 /// <param name="statementId">The statement id.</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
 /// <param name="keyProperty">The property of the result object to be used as the key.</param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate">A delegate called once per row in the QueryForDictionary method&gt;</param>
 /// <returns>
 /// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
 /// </returns>
 /// <exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public IDictionary <K, V> QueryForDictionary <K, V>(string statementId, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate <K, V> rowDelegate)
 {
     using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
     {
         IMappedStatement statement = GetMappedStatement(statementId);
         return(statement.ExecuteQueryForDictionary(sessionScope.Session, parameterObject, keyProperty, valueProperty, rowDelegate));
     }
 }
Beispiel #5
0
        public static DataTable RunQueryForDataTableWithPage(this IDataMapper mapper, string tag, object paramObject, string orderby, int willShowedPage, int pageSize, ref int totalCount)
        {
            DataMapper       dataMaper       = (DataMapper)mapper;
            IMappedStatement mappedStatement = dataMaper.GetMappedStatement(tag);

            using (var sessionScope = new DataMapperLocalSessionScope(mappedStatement.ModelStore.SessionStore, mappedStatement.ModelStore.SessionFactory))
            {
                return(mappedStatement.RunQueryForDataTableWithPage(sessionScope.Session, paramObject, orderby, willShowedPage, pageSize, ref totalCount));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Executes a Sql SELECT statement that returns data to populate
        /// a number of result objects.
        /// <p/>
        /// The parameter object is generally used to supply the input
        /// data for the WHERE clause parameter(s) of the SELECT statement.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="statementId">The statement id.</param>
        /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
        /// <param name="resultObject">An Ilist object used to hold the objects.</param>
        public void QueryForList <T>(string statementId, object parameterObject, IList <T> resultObject)
        {
            if (resultObject == null)
            {
                throw new DataMapperException("resultObject parameter must be instantiated before being passed to SqlMapper.QueryForList");
            }

            using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
            {
                IMappedStatement statement = GetMappedStatement(statementId);
                statement.ExecuteQueryForList(sessionScope.Session, parameterObject, resultObject);
            }
        }