public virtual void Insert(T entity) { try { if (entity == null) { throw new ArgumentNullException("entity"); } Entities.Add(entity); if (Context == null || _isDisposed) { Context = new LMSContentEntities(); } //Context.SaveChanges(); commented out call to SaveChanges as Context save changes will be //called with Unit of work } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { _errorMessage.Append(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine); } } throw new Exception(_errorMessage.ToString(), dbEx); } }
public GenericRepository(LMSContentEntities context) { _isDisposed = false; Context = context; }