Beispiel #1
0
        private void GenerateInsertStatement(object parameters)
        {
            var columns = new List <string>();
            var values  = new List <string>();

            foreach (var propInfo in parameters.GetType().GetProperties().Where(x => x.Name != "Id").OrderBy(x => x.Name))
            {
                var name  = propInfo.Name;
                var value = propInfo.GetValue(parameters, null);

                var paramterName = AddParameter(name, value);

                columns.Add($"[{name}]");
                values.Add($"@{paramterName}");
            }

            AddLine($"INSERT INTO {TableNameHelper.GenerateTableName<TClass>()} ({string.Join(",", columns.ToArray())}) ");
            AddLine($"VALUES ({string.Join(",", values.ToArray())})");
            AddLine("SELECT CAST(SCOPE_IDENTITY() AS INT)");
        }
Beispiel #2
0
        public SelectBuilder(IDbConnection dbConnection)
        {
            _dbConnection = dbConnection;

            AddLine($"SELECT * FROM {TableNameHelper.GenerateTableName<TClass>()}");
        }
Beispiel #3
0
        public UpdateBuilder(IDbConnection dbConnection)
        {
            _dbConnection = dbConnection;

            AddLine($"UPDATE {TableNameHelper.GenerateTableName<TClass>()} SET ");
        }
Beispiel #4
0
 public static string GetTableName <TClass>()
 {
     return(TableNameHelper.GenerateTableName <TClass>());
 }
Beispiel #5
0
        public DeleteBuilder(IDbConnection dbConnection)
        {
            _dbConnection = dbConnection;

            AddLine($"DELETE FROM {TableNameHelper.GenerateTableName<TClass>()}");
        }