コード例 #1
0
        public void Update()
        {
            var command = UpdateGenerator.Generate(new Foo
            {
                Id   = 5,
                Foo1 = "foo1",
                Foo2 = "foo2"
            });

            Assert.AreEqual("UPDATE Foo SET Foo1 = @Foo1, Foo2 = @Foo2 WHERE Id = @Id;", command);
        }
コード例 #2
0
ファイル: DapperExtensions.cs プロジェクト: Kunze/MoreDapper
        /// <summary>
        /// Update 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 UpdateSingle <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.Update, out cachedCommand);

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

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