Ejemplo n.º 1
0
 /// <summary>
 /// Bulk insert weapper for the database specialisation type.
 /// </summary>
 /// <typeparam name="T">Type of the object to insert</typeparam>
 /// <param name="db">DB model</param>
 /// <param name="collection">DbSet into which we're inserting the objects</param>
 /// <param name="itemsToSave">Objects to insert</param>
 /// <returns>True if the insert succeeded</returns>
 public bool BulkInsert <T>(BaseDBModel db, DbSet <T> collection, List <T> itemsToSave) where T : class
 {
     try
     {
         db.BulkInsert(itemsToSave);
         return(true);
     }
     catch (Exception ex)
     {
         Logging.LogError($"Exception bulk inserting {typeof(T)}: {ex.Message}");
         return(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// SQLite bulk insert uses EF Extensions BulkIndex.
        /// This would also work for SQLServer.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="itemsToSave"></param>
        /// <returns></returns>
        public bool BulkInsert <T>(BaseDBModel db, DbSet <T> collection, List <T> itemsToSave) where T : class
        {
            if (BaseDBModel.ReadOnly)
            {
                Logging.LogVerbose("Read-only mode - no data will be inserted.");
                return(true);
            }

            bool success = false;

            try
            {
                db.BulkInsert(itemsToSave);
                success = true;
            }
            catch (Exception ex)
            {
                Logging.LogError("Exception during bulk insert: {0}", ex.Message);
            }

            return(success);
        }