示例#1
0
        private static void SetCommandText <T>(IDbCommand command, T example)
        {
            var dialect = Tuxedo.Dialect;

            Tuxedo.Dialect      = Dialect;
            command.CommandText = Tuxedo.Insert(example).Sql;
            Tuxedo.Dialect      = dialect;
        }
示例#2
0
        public void Insert_one()
        {
            var query = Tuxedo.Insert(new User {
                Email = "*****@*****.**"
            });

            Assert.AreEqual("INSERT INTO User (Email) VALUES (@Email)", query.Sql);
            Assert.AreEqual(1, query.Parameters.Count);
            Assert.AreEqual("*****@*****.**", query.Parameters["@Email"]);
            Console.WriteLine(query);
        }
        public static T Insert <T>(this IDbConnection connection, T entity, IDbTransaction transaction = null, int?commandTimeout = null) where T : class
        {
            var descriptor = Tuxedo.GetDescriptor <T>();
            var insert     = Tuxedo.Insert(entity);
            var sql        = insert.Sql;

            if (descriptor.Identity != null)
            {
                sql = string.Concat(sql, "; ", Tuxedo.Identity());
                var result = connection.Query <int>(sql, Prepare(insert.Parameters), transaction, true, commandTimeout).Single();
                MapBackId(descriptor, entity, result);
            }
            else
            {
                connection.Execute(sql, Prepare(insert.Parameters), transaction, commandTimeout);
            }
            return(entity);
        }