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)"); }
public SelectBuilder(IDbConnection dbConnection) { _dbConnection = dbConnection; AddLine($"SELECT * FROM {TableNameHelper.GenerateTableName<TClass>()}"); }
public UpdateBuilder(IDbConnection dbConnection) { _dbConnection = dbConnection; AddLine($"UPDATE {TableNameHelper.GenerateTableName<TClass>()} SET "); }
public static string GetTableName <TClass>() { return(TableNameHelper.GenerateTableName <TClass>()); }
public DeleteBuilder(IDbConnection dbConnection) { _dbConnection = dbConnection; AddLine($"DELETE FROM {TableNameHelper.GenerateTableName<TClass>()}"); }