Esempio n. 1
0
        /// <summary>
        /// Gets the parent for the given entity and link.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        public object GetParent(object entity, ChildToParentEntityLink link, EntityField[] fields)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            // check...
            if (EntityType == null)
            {
                throw new ArgumentNullException("EntityType");
            }
            this.EntityType.AssertIsOfType(entity);

            // get the link type...
            if (link.ParentEntityType == null)
            {
                throw new ArgumentNullException("link.ParentEntityType");
            }

            // do we cache?
            //if (link.ParentEntityType.HasCache)
            //    return this.GetParentFromCache(entity, link, link.ParentEntityType, link.ParentEntityType.Cache);
            //else
            return(this.LoadParent(entity, link));
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="Link"></param>
        public ChildToParentEntityLinkPropertyDescriptor(ChildToParentEntityLink link) : base(link.Name, new Attribute[] {})
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // set...
            _link = link;
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the parent for the given entity.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        protected override object LoadParent(object entity, ChildToParentEntityLink link)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // defer...
            return(SqlFilter.CreateGetParentFilter(entity, link).ExecuteEntity());
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the parent for the given entity and link.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        public object GetParent(object entity, ChildToParentEntityLink link)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (EntityType == null)
            {
                throw new ArgumentNullException("EntityType");
            }
            this.EntityType.AssertIsOfType(entity);

            // return...
            return(((Entity)entity).GetParent(link));
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the parent for the given entity and link.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        public void SetParent(object entity, ChildToParentEntityLink link, object newParent)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (EntityType == null)
            {
                throw new ArgumentNullException("EntityType");
            }
            this.EntityType.AssertIsOfType(entity);

            // set...
            ((Entity)entity).SetParent(link, newParent);
        }
Esempio n. 6
0
        /// <summary>
        /// Pushes a value back down to the underlying field.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="value"></param>
        private void PushValue(ChildToParentEntityLink link, object value)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // get storage...
            IEntityStorage storage = this.Storage;

            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            // set...
            storage.SetParent(this.Entity, link, value);
        }
Esempio n. 7
0
        /// <summary>
        /// Pulls the value from the entity.
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        private object PullValue(ChildToParentEntityLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // check...
            if (Entity == null)
            {
                throw new ArgumentNullException("Entity");
            }

            // get persistence...
            IEntityStorage storage = this.Storage;

            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            // get...
            return(storage.GetParent(this.Entity, link));
        }
Esempio n. 8
0
        ///// <summary>
        ///// Gets the parent object from the cache.
        ///// </summary>
        ///// <param name="entity"></param>
        ///// <param name="link"></param>
        ///// <returns></returns>
        //private object GetParentFromCache(object entity, ChildToParentEntityLink link, EntityType parentEntityType, EntityCache parentCache)
        //{
        //    if(entity == null)
        //        throw new ArgumentNullException("entity");
        //    if(link == null)
        //        throw new ArgumentNullException("link");
        //    if(parentEntityType == null)
        //        throw new ArgumentNullException("parentEntityType");
        //    if(parentCache == null)
        //        throw new ArgumentNullException("parentCache");

        //    // what are we trying to get?
        //    EntityField[] linkFields = link.GetLinkFields();
        //    if (linkFields == null)
        //        throw new InvalidOperationException("'linkFields' is null.");
        //    if (linkFields.Length != 1)
        //        throw new InvalidOperationException("'linkFields' is an invalid length.");

        //    // get the values...
        //    if(EntityType.Storage == null)
        //        throw new ArgumentNullException("EntityType.Storage");
        //    object[] foreignKey = this.EntityType.Storage.GetValues(entity, linkFields);

        //    // contains?
        //    object parent = parentCache[foreignKey[0]];
        //    if(parent == null)
        //        parent = this.LoadParent(entity, link);

        //    // return...
        //    return parent;
        //}

        /// <summary>
        /// Loads the parent entity from the underlying store.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        protected abstract object LoadParent(object entity, ChildToParentEntityLink link);
Esempio n. 9
0
 /// <summary>
 /// Gets the parent for the given entity and link.
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="link"></param>
 /// <returns></returns>
 public object GetParent(object entity, ChildToParentEntityLink link)
 {
     return(this.GetParent(entity, link, new EntityField[] {}));
 }