Ejemplo n.º 1
0
        /// <summary>
        /// Removes specified data object.
        /// </summary>
        /// <param name="context">ObjectContext object</param>
        /// <param name="obj">Data object to remove</param>
        /// <returns>
        /// entity set name
        /// </returns>
        public static void RemoveObject(ObjectContext context,
                                        DataObject obj)
        {
            Debug.Assert(context != null);

            context.DeleteObject(DataObjectHelper.GetEntityObject(obj));
        }
Ejemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds data object to object context.
        /// </summary>
        /// <param name="dataObject">
        /// DataObject object to add.
        /// </param>
        protected void AddObject(DataObject dataObject)
        {
            Debug.Assert(dataObject != null);

            // add entity object to context
            _context.AddObject(_fullEntitySet, DataObjectHelper.GetEntityObject(
                                   dataObject));
        }
        private bool _CanAddObject(TDataObject dataObject)
        {
            if (_filter == null)
            {
                return(true);
            }

            var entity = (TEntity)DataObjectHelper.GetEntityObject(dataObject);

            return(_filter(entity));
        }
        /// <summary>
        /// Removes data object from the collection.
        /// </summary>
        public virtual bool Remove(T dataObject)
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException();
            }

            _CheckReadOnlyFlag();

            return(_entities.Remove(DataObjectHelper.GetEntityObject(
                                        dataObject) as TEntity));
        }
        /// <summary>
        /// Adds data object to the collection.
        /// </summary>
        public virtual void Add(T dataObject)
        {
            if (dataObject == null)
            {
                throw new ArgumentNullException();
            }

            _CheckReadOnlyFlag();

            _entities.Add(DataObjectHelper.GetEntityObject(
                              dataObject) as TEntity);
        }
Ejemplo n.º 6
0
        private void _SetValue(TDataObj dataObject)
        {
            TEntity entity = null;

            if (dataObject != null)
            {
                entity = DataObjectHelper.GetEntityObject(dataObject) as TEntity;
                if (entity == null)
                {
                    throw new DataException(Properties.Messages.Error_InvalidDataObjectInstance);
                }
            }

            _entityRef.Value = entity;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Removes data object from object context.
        /// </summary>
        /// <param name="dataObject">
        /// DataObject object to remove.
        /// </param>
        protected void RemoveObject(DataObject dataObject)
        {
            Debug.Assert(dataObject != null);

            EntityObject entity = DataObjectHelper.GetEntityObject(
                dataObject);

            // remove data object from cache
            // TODO: entity stays in context until SaveChanges is called,
            // so alternatively we can sync. cache with context handling
            // SavingChanges event.
            //_context.Cache.RemoveObject(entity);

            // remove entity object from context
            _context.DeleteObject(entity);
        }
Ejemplo n.º 8
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public void AddObject(T dataObject)
        {
            EntityObject entity = DataObjectHelper.GetEntityObject(dataObject);

            // check if entity already added
            // entity could be implicitly added by setting a relation object
            if (!_ContainsEntity(entity))
            {
                base.AddObject(dataObject);
            }
            else
            {
                // emulate Add event
                _NotifyContextCollectionChanged(CollectionChangeAction.Add,
                                                dataObject);
            }
        }