/// <summary>
        /// Initializes a new instance of the EntityRef class
        /// </summary>
        /// <param name="parent">The entity that this association is a member of</param>
        /// <param name="memberName">The name of this EntityRef member on the parent entity</param>
        /// <param name="entityPredicate">The function used to filter the associated entity.</param>
        public EntityRef(Entity parent, string memberName, Func <TEntity, bool> entityPredicate)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (string.IsNullOrEmpty(memberName))
            {
                throw new ArgumentNullException("memberName");
            }
            if (entityPredicate == null)
            {
                throw new ArgumentNullException("entityPredicate");
            }

            this._parent          = parent;
            this._entityPredicate = entityPredicate;
            this._memberName      = memberName;

            PropertyInfo propInfo = this._parent.GetType().GetProperty(memberName, OpenRiaServices.DomainServices.Client.MetaType.MemberBindingFlags);

            if (propInfo == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.Property_Does_Not_Exist, parent.GetType(), memberName), "memberName");
            }
            this._assocAttribute = propInfo.GetCustomAttributes(false).OfType <AssociationAttribute>().SingleOrDefault();
            if (this._assocAttribute == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.MemberMustBeAssociation, memberName), "memberName");
            }

            this._isComposition = propInfo.GetCustomAttributes(typeof(CompositionAttribute), false).Any();

            // register our callback so we'll be notified whenever the
            // parent entity is added or removed from an EntitySet
            this._parent.RegisterSetChangedCallback(this.OnEntitySetChanged);

            this._parent.SetEntityRef(memberName, this);

            this._parent.PropertyChanged += this.ParentEntityPropertyChanged;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the EntityRef class
        /// </summary>
        /// <param name="parent">The entity that this association is a member of</param>
        /// <param name="memberName">The name of this EntityRef member on the parent entity</param>
        /// <param name="entityPredicate">The function used to filter the associated entity.</param>
        public EntityRef(Entity parent, string memberName, Func <TEntity, bool> entityPredicate)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (string.IsNullOrEmpty(memberName))
            {
                throw new ArgumentNullException(nameof(memberName));
            }
            if (entityPredicate == null)
            {
                throw new ArgumentNullException(nameof(entityPredicate));
            }

            this._parent          = parent;
            this._entityPredicate = entityPredicate;
            this._metaMember      = this._parent.MetaType[memberName];

            if (this._metaMember == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.Property_Does_Not_Exist, parent.GetType(), memberName), nameof(memberName));
            }
            if (this._metaMember.AssociationAttribute == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.MemberMustBeAssociation, memberName), nameof(memberName));
            }

            // register our callback so we'll be notified whenever the
            // parent entity is added or removed from an EntitySet
            this._parent.RegisterSetChangedCallback(this.OnEntitySetChanged);

            this._parent.SetEntityRef(memberName, this);

            this._parent.PropertyChanged += this.ParentEntityPropertyChanged;
        }