Ejemplo n.º 1
0
        public static void UpdateAll(List <MagicNumber> ListInstanceData)
        {
            ListInstanceData = CheckInsertAll(ListInstanceData, true);
            if (ListInstanceData.Count < 1)
            {
                return;
            }

            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;
                    foreach (var item in ListInstanceData)
                    {
                        db.Table_Name.Attach(item);
                        db.Entry(item).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), ListInstanceData.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Ejemplo n.º 2
0
        public static void UpdateByInstance(MagicNumber instanceData)
        {
            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    db.Table_Name.Attach(instanceData);
                    db.Entry(instanceData).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), instanceData.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Ejemplo n.º 3
0
        public static void RemoveAll()
        {
            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;

                var query = from b in db.Table_Name
                            orderby b.Symbol
                            select b;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;
                    foreach (var item in query)
                    {
                        db.Table_Name.Attach(item);
                        db.Entry(item).State = EntityState.Deleted;
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), query.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Ejemplo n.º 4
0
 public static void AddInstance(MagicNumber instanceData)
 {
     using (var db = new MagicNumberContext())
     {
         try
         {
             db.Table_Name.Add(instanceData);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             DateTime localDate   = DateTime.Now;
             string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), instanceData.ToString());
             PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
         }
     }
 }
Ejemplo n.º 5
0
        public static void RemoveByInstance(MagicNumber instanceData)
        {
            using (var db = new MagicNumberContext())
            {
                bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled;
                try
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    db.Table_Name.Attach(instanceData);
                    db.Entry(instanceData).State = EntityState.Deleted;
                    db.SaveChanges();
                }
                finally
                {
                    db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                }
            }
        }
Ejemplo n.º 6
0
        public static void AddAllInstance(List <MagicNumber> ListInstanceData)
        {
            ListInstanceData = CheckInsertAll(ListInstanceData);
            if (ListInstanceData.Count < 1)
            {
                return;
            }

            using (var db = new MagicNumberContext())
            {
                try
                {
                    db.Table_Name.AddRange(ListInstanceData);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DateTime localDate   = DateTime.Now;
                    string   printResult = String.Format("{0}\n{1}\n\n{2}", localDate.ToString(), ex.ToString(), ListInstanceData.ToString());
                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                }
            }
        }