/// <summary> /// Writes the current object to the database using the table named in the DALTable attribute. /// </summary> /// <param name="ExistingConnection">An existing and open connection to use when writing this data.</param> /// <param name="SqlTransaction">An optional transaction to write to the database under.</param> /// <returns>The number of rows written to the database.</returns> public int WriteToDatabase(MySqlConnection ExistingConnection, MySqlTransaction SqlTransaction = null) { return(DataOutputOperations.BulkTableWrite(ExistingConnection, this, SqlTransaction: SqlTransaction, ForceType: this.GetType())); }
public static int WriteToDatabase <T>(this IEnumerable <T> DbModelData, MySqlConnection ExistingConnection, MySqlTransaction SqlTransaction = null) where T : DALBaseModel { return(DataOutputOperations.BulkTableWrite <T>(ExistingConnection, DbModelData, SqlTransaction: SqlTransaction)); }
/* * /// <summary> * /// Takes in an object and gets the full info about its properties, including the underscore names. * /// </summary> * /// <param name="TargetObject">The object to pull the properties from.</param> * /// <param name="GetOnlyDbResolvables">Indicate to get only properties marked with the DALResolvable attribute.</param> * /// <returns>The full list of property info including underscore names.</returns> * public static List<KeyValuePair<string, Tuple<string, PropertyInfo>>> GetUnderscorePropertiesOfObject(object TargetObject, bool GetOnlyDbResolvables = true) * { * //TODO: investigate whether it makes sense to look for the DALResolvable attribute or to just attempt to convert all class properties * // get all properties marked with the DALResolvable attribute * var convertableProperties = TargetObject * .GetType() * .GetProperties() * .Where(x => !GetOnlyDbResolvables || x.GetCustomAttributes(true).Any(y => new Type[] { typeof(DALResolvable) }.Contains(y.GetType()))) * .ToList(); * * // get the underscore names of all properties * var underscoreNames = convertableProperties * .ToDictionary(x => x.Name.StartsWith("InternalId") ? x.Name : Regex.Replace(x.Name, UnderscoreNamesHelper.UppercaseSearchPattern, UnderscoreNamesHelper.ReplacePattern), x => new Tuple<string, PropertyInfo>(x.Name, x)) * .ToList(); * * return underscoreNames; * } */ /// <summary> /// Writes the current object to the database using the table named in the DALTable attribute. /// </summary> /// <param name="ConnectionStringType">Type of connection to use.</param> /// <returns>The number of rows written to the database.</returns> public int WriteToDatabase(Enum ConnectionStringType) { return(DataOutputOperations.BulkTableWrite(ConnectionStringType, this, ForceType: this.GetType())); }
public static int WriteToDatabase <T>(this IEnumerable <T> DbModelData, Enum ConnectionStringType) where T : DALBaseModel { return(DataOutputOperations.BulkTableWrite <T>(ConnectionStringType, DbModelData)); }
/// <summary> /// Writes out a list of objects to the database using a combination of supplied parameters and class attributes. /// </summary> /// <typeparam name="T">The type of object to write.</typeparam> /// <param name="ConfigConnectionString">An enum type to reference a connection string defined in web.config.</param> /// <param name="SourceData">The list of objects to write out to the database.</param> /// <param name="TableName">The name of the table to write to. If none is supplied, DALHelper attempts to get it from the DALTable attribute.</param> /// <param name="ForceType">Force a type other than the specified one to be used when auto-retrieving the table name from the DALTable attribute.</param> /// <returns>The total number of rows written to the database.</returns> public static int BulkTableWrite <T>(Enum ConfigConnectionString, IEnumerable <T> SourceData, string TableName = null, Type ForceType = null) => DataOutputOperations.BulkTableWrite <T>(ConfigConnectionString, SourceData, TableName, ForceType);
/// <summary> /// Writes out a list of objects to the database using a combination of supplied parameters and class attributes. /// </summary> /// <typeparam name="T">The type of object to write.</typeparam> /// <param name="EstablishedConnection">An open and established connection to a MySQL database.</param> /// <param name="SourceData">The list of objects to write out to the database.</param> /// <param name="TableName">The name of the table to write to. If none is supplied, DALHelper attempts to get it from the DALTable attribute.</param> /// <param name="SqlTransaction">Supply an existing transaction for use in this operation.</param> /// <param name="ForceType">Force a type other than the specified one to be used when auto-retrieving the table name from the DALTable attribute.</param> /// <returns>The total number of rows written to the database.</returns> public static int BulkTableWrite <T>(MySqlConnection EstablishedConnection, IEnumerable <T> SourceData, string TableName = null, MySqlTransaction SqlTransaction = null, Type ForceType = null) => DataOutputOperations.BulkTableWrite <T>(EstablishedConnection, SourceData, TableName, SqlTransaction, ForceType);
/// <summary> /// Gets a partially configured BulkTableWriter objects which can then be used to write data to the database. /// </summary> /// <typeparam name="T">The type of object to write.</typeparam> /// <param name="EstablishedConnection">An open and established connection to a MySQL database.</param> /// <param name="InsertQuery">The full SQL query to be run on each row insert.</param> /// <param name="ThrowException">Throw exception or cache in LastExecutionException and continue.</param> /// <param name="UseTransaction">Indicate whether to write all the data in a single transaction.</param> /// <param name="SqlTransaction">Supply an existing transaction for use in this operation.</param> /// <returns>An object to used to write data to the database.</returns> public static BulkTableWriter <T> GetBulkTableWriter <T>(MySqlConnection EstablishedConnection, string InsertQuery = null, bool ThrowException = true, bool UseTransaction = true, MySqlTransaction SqlTransaction = null) => DataOutputOperations.GetBulkTableWriter <T>(EstablishedConnection, InsertQuery: InsertQuery, UseTransaction: UseTransaction, ThrowException: ThrowException, SqlTransaction: SqlTransaction);
//***************** Table write functions *****************// /// <summary> /// Gets a partially configured BulkTableWriter objects which can then be used to write data to the database. /// </summary> /// <typeparam name="T">The type of object to write.</typeparam> /// <param name="ConfigConnectionString">An enum type to reference a connection string defined in web.config.</param> /// <param name="InsertQuery">The full SQL query to be run on each row insert.</param> /// <param name="UseTransaction">Indicate whether to write all the data in a single transaction.</param> /// <param name="ThrowException">Throw exception or cache in LastExecutionException and continue.</param> /// <param name="AllowUserVariables">Will allow special user variables (variables start with "@") to be defined in the query that will be eventually executed.</param> /// <returns>An object to used to write data to the database.</returns> public static BulkTableWriter <T> GetBulkTableWriter <T>(Enum ConfigConnectionString, string InsertQuery = null, bool UseTransaction = false, bool ThrowException = true, bool AllowUserVariables = false) => DataOutputOperations.GetBulkTableWriter <T>(ConfigConnectionString, InsertQuery: InsertQuery, UseTransaction: UseTransaction, ThrowException: ThrowException, AllowUserVariables: AllowUserVariables);