示例#1
0
        /// <summary>
        /// Inserts an entity into table "Ts" and returns identity id.
        /// </summary>
        /// <param name="connection">Open SqlConnection</param>
        /// <param name="entityToInsert">Entity to insert</param>
        /// <returns>Identity of inserted entity</returns>
        public static long Insert <T>(this IDbConnection connection, T entityToInsert, IDbTransaction transaction = null, int?commandTimeout = null) where T : class
        {
            var         type    = typeof(T);
            ISqlAdapter adapter = GetFormatter(connection);
            SqlEscape   escape  = GetEscape(connection);
            var         cmd     = InsertQueriesCache(type, escape);

            return(connection.ExecuteScalar <long>(string.Format("{0};{1}", cmd, adapter.GetIdentity()), entityToInsert, transaction: transaction, commandTimeout: commandTimeout));
        }