Esempio n. 1
0
        public void AddContact(Contact c)
        {
            try
            {
                DbEntityValidationResult vresult = _enitites.Entry(c).GetValidationResult();

                if (vresult.IsValid)
                {
                    _enitites.Contacts.Add(c);
                    _enitites.SaveChanges();
                }
                else
                {
                    //Console.WriteLine(vresult.ValidationErrors.First().ErrorMessage);

                    foreach (DbValidationError item in vresult.ValidationErrors)
                    {
                        Console.WriteLine(item.ErrorMessage);
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("Errue générale " + ex.Message);
            }
            finally
            {
                Trace.Write("tentative d'ajout");
            }
        }
Esempio n. 2
0
        public static void Update2(Contact c)
        {
            using (DBContactEntities entities = new DBContactEntities())
            {
                //Classe de performances
                Stopwatch sw = new Stopwatch();
                sw.Start();

                //Pour les performances desactiver Le tracking pourpasser en self
                entities.Configuration.AutoDetectChangesEnabled = false;

                entities.Contacts.Attach(c);

                Console.WriteLine(entities.Entry(c).State);

                c.Adresse = "NEW ADRESS";

                Console.WriteLine(entities.Entry(c).State);

                entities.SaveChanges();

                //Affiche les performances
                sw.Stop();
                Console.WriteLine(sw.Elapsed.TotalMilliseconds.ToString());
            }
        }
Esempio n. 3
0
 public static void AddTel(Contact c, string numero)
 {
     using (DBContactEntities entities = new DBContactEntities())
     {
         entities.Contact.Attach(c);
         c.Telephone.Add(new Telephone()
         {
             numero = numero
         });
         entities.SaveChanges();
     }
 }
Esempio n. 4
0
        static public void UpdateContact(Contact c)
        {
            using (DBContactEntities entities = new DBContactEntities())
            {
                entities.Entry(c).State = System.Data.Entity.EntityState.Modified;

                Console.WriteLine(entities.Entry(c).State);

                Console.WriteLine("DataBase Values :");
                PrintProp(entities.Entry(c).GetDatabaseValues());

                Console.WriteLine("Current Values :");
                PrintProp(entities.Entry(c).CurrentValues);

                entities.SaveChanges();
            }
        }