Ejemplo n.º 1
0
        public void Delete()
        {
            var command = DeleteGenerator.Generate(new Foo
            {
                Id   = 5,
                Foo1 = "foo1",
                Foo2 = "foo2"
            });

            Assert.AreEqual("DELETE FROM Foo WHERE Id = @Id;", command);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete a single row
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="param">object</param>
        /// <param name="table">Optional table name</param>
        /// <param name="commandTimeout">commandTimeout</param>
        /// <param name="transaction">transaction</param>
        /// <returns>Numbers of rows affected</returns>
        public static int DeleteSingle <T>(this IDbConnection connection, T param, int?commandTimeout = null, IDbTransaction transaction = null)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param can not be null.");
            }

            if (param is IEnumerable)
            {
                throw new ArgumentException("param can not be a IEnumerable.");
            }

            var    type = typeof(T);
            string cachedCommand;
            var    value = StringCache.TryGetCommand(type, Operation.Delete, out cachedCommand);

            if (string.IsNullOrEmpty(cachedCommand))
            {
                cachedCommand = DeleteGenerator.Generate(param);
                StringCache.Add(type, Operation.Delete, cachedCommand);
            }

            return(connection.Execute(cachedCommand, param, commandTimeout: commandTimeout, transaction: transaction));
        }