/// <summary> /// Executes a nonquery stored procedure and returns the number of rows affected in the database /// <para> /// Optional: Sets the custom configuration name <seealso cref="SQLAdapterConfiguration.SetConfig(string, string)"/> /// </para> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="clazz"></param> /// <param name="storedProcedureName"></param> /// <param name="adapterConfigurationFileName"></param> /// <returns></returns> public static int Push <T>(this T clazz, string storedProcedureName, string adapterConfigurationFileName = "SqlDataAdapter.config", string adapterConfigurationFilePath = "") where T : ColumnMap { SQLAdapterConfiguration.SetConfig(adapterConfigurationFileName, adapterConfigurationFilePath); Command cmd = new Command(storedProcedureName); return(DAO.ExecuteNonQuery(cmd.ToCommand(clazz))); }
/// <summary> /// sets the default of the command object from the app config /// program.DefaultConnectionString defines the app config key for the default connectin string /// </summary> public void BuildConnection() { string defaultConnectionName = SQLAdapterConfiguration.AppSettings().Settings[DefaultConnectionStringKey].Value; string connectionString = SQLAdapterConfiguration.ConnectionStrings()[defaultConnectionName].ConnectionString; command.Connection = new SqlConnection(connectionString); }
/// <summary> /// Populates a single instance of class T using the first record of the results of the executed stored procedure /// <para> /// Optional: Sets the custom configuration name <seealso cref="SQLAdapterConfiguration.SetConfig(string, string)"/> /// </para> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="clazz"></param> /// <param name="storedProcedureName"></param> /// <param name="adapterConfigurationFileName"></param> /// <returns></returns> public static T Populate <T>(this T clazz, string storedProcedureName, string adapterConfigurationFileName = "SqlDataAdapter.config", string adapterConfigurationFilePath = "") where T : ColumnMap { SQLAdapterConfiguration.SetConfig(adapterConfigurationFileName, adapterConfigurationFilePath); Command cmd = new Command(storedProcedureName); T result = DAO.ExecuteQuery(cmd.ToCommand(clazz)).ToColumnMap(clazz); cmd.Dispose(); return(result); }
private static void SetParameterFromField <T>(Command cmd, T clazz, List <string> storedProcedureParameters) where T : ColumnMap { foreach (FieldInfo f in typeof(T).GetFields()) { ColumnMap attr = (ColumnMap)Attribute.GetCustomAttribute(f, typeof(ColumnMap)); if (attr != null) { if (attr.parameter != null && storedProcedureParameters.Contains(attr.parameter)) { cmd.AddParameter(attr.parameter, f.GetValue(clazz)); } else if (attr.Name != null && SQLAdapterConfiguration.ColumnMappings().ColumnMap[attr.Name] != null) { string columnParameterName = SQLAdapterConfiguration.ColumnMappings().ColumnMap[attr.Name].ParameterName; if (storedProcedureParameters.Contains(columnParameterName)) { cmd.AddParameter(columnParameterName, f.GetValue(clazz)); } } } } }