public void Test1()
        {
            var b = new SqlBuilder();
            var p = new {a = 123};
            var t = b.AddTemplate("select @a {{WHERE}}", p);

            b.Where("@b = @c", new {b = "abc", c = "abc"});

            int res;
            using (var db = new SqlConnection(ConnectionStrings.Default))
                res = db.Query<int>(t.RawSql, t.Parameters).Single();
            Assert.AreEqual(p.a, res);
        }
Пример #2
0
        protected int RetrieveCountOfRowsWithTheValue(int firstValue)
        {
            var createdConnection = new SqlConnection(Connection);
            var neededCommand = new SqlCommand("SELECT COUNT(SomeId) FROM SomeTable WHERE FirstColumn = @FirstColumn", createdConnection);

            var parameters = new[] { new SqlParameter("@FirstColumn", firstValue) };
            var result = 0;

            neededCommand.Parameters.AddRange(parameters);
            try
            {
                createdConnection.Open();
                result = ((int)neededCommand.ExecuteScalar());
            }
            finally
            {
                createdConnection.Close();
            }

            return result;
        }