示例#1
0
 public static async Task BulkCopyAsync <T>(this DbContext context, IEnumerable <T> entities)
 {
     try
     {
         var copy = CopyFactory.GetCopy <T>(context);
         await copy.InsertAsync(entities).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         throw new CopyException(e);
     }
 }
示例#2
0
        // Entry point of program execution
        static void Main(string[] args)
        {
            try
            {
                // Create and print sample Employee
                Employee emp = CreateEmployeeObject();
                WriteLine(emp);

                PrintCopyMethods();
                WriteLine("Choose Copy Method");

                string copyMethod      = ReadLine();
                int    copyMethodValue = ValidateAndConvertInput(copyMethod,
                                                                 maxRange: SystemConstants.MaxCopyMethods,
                                                                 message: SystemConstants.InvalidMethodError);

                ICopyFactory copyFactory = CopyFactory.GetCopyMethod((CopyMethodsEnum)copyMethodValue); //Manual parse with vaidation

                //Creating Employee copy based on the user input method
                Employee empCopy = copyFactory.CopyObject <Employee>(emp);
                WriteLine(empCopy);
            }
            // Handled Exceptions
            catch (CustomException ce)
            {
                // Log Error
                WriteLine(ce.Message);
            }
            // Unhandled Exceptions(Error)
            catch (Exception e)
            {
                // Log Error
                WriteLine(SystemConstants.GeneralErrorMessage);
            }

            ReadKey();
        }