Example #1
0
 public bool Insert(Product entity)
 {
     try
     {
         // Your code...
         // Could also be before try if you know the exception occurs in SaveChanges
         db.Products.Add(entity);
         db.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(false);
     }
     return(true);
 }
Example #2
0
 public bool Insert(Content entity)
 {
     db.Contents.Add(entity);
     db.SaveChanges();
     return(true);
 }
Example #3
0
 public bool Insert(Category entity)
 {
     db.Categories.Add(entity);
     db.SaveChanges();
     return(true);
 }
Example #4
0
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }