/// <summary> /// Insert a ingle 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 InsertSingle <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. Call InsertMany instead."); } var type = typeof(T); string cachedCommand; var value = StringCache.TryGetCommand(type, Operation.Insert, out cachedCommand); if (string.IsNullOrEmpty(cachedCommand)) { cachedCommand = InsertGenerator.GenerateSingle(param); StringCache.Add(type, Operation.Insert, cachedCommand); } return(connection.Execute(cachedCommand, param, commandTimeout: commandTimeout, transaction: transaction)); }
public void AddCommand() { var type = typeof(Foo); StringCache.Add(type, Operation.Insert, "insert 1"); StringCache.Add(type, Operation.Insert, "insert 2"); string cachedCommand; var value = StringCache.TryGetCommand(type, Operation.Insert, out cachedCommand); Assert.AreEqual(true, value); Assert.AreEqual("insert 1", cachedCommand); }