Exemple #1
0
        public void Create(T entity)
        {
            try
            {
                service.AddObject(entity);

                service.SaveChanges(SaveChangesOptions.None);
            }
            catch (Exception)
            {
                // if entity was attached to service, but error occured while creating this entity, we must deattach entity from service to be able to create entities with this service
                if (service.IsAttached(entity))
                {
                    service.Detach(entity);
                }

                throw;
            }
        }
Exemple #2
0
        private void Update()
        {
            var user = GetUserEntity(UserId, _context);

            user.SetAttributeValue(AttributeMapApproved, Approved);
            user.SetAttributeValue(AttributeMapLastLogin, LastLogin.ToUniversalTime());

            _context.Attach(user);
            _context.UpdateObject(user);
            _context.SaveChanges();
            _context.Detach(user);
        }