Exemplo n.º 1
0
        internal SqlJoin(string alias, JoinType type, ChildToParentEntityLink link)
            : this(alias, type)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // set...
            _targetMember = link;

            // et...
            _targetEntityType = link.ParentEntityType;
            if (_targetEntityType == null)
            {
                throw new InvalidOperationException("_targetEntityType is null.");
            }

            // keys...
            _targetKeyFields = _targetEntityType.GetKeyFields();
            if (_targetKeyFields == null)
            {
                throw new InvalidOperationException("'_targetKeyFields' is null.");
            }
            if (_targetKeyFields.Length == 0)
            {
                throw new InvalidOperationException("'_targetKeyFields' is zero-length.");
            }

            // get...
            _sourceFields = link.GetLinkFields();
            if (_sourceFields == null)
            {
                throw new InvalidOperationException("_sourceFields is null.");
            }
            if (_targetKeyFields.Length != _sourceFields.Length)
            {
                throw new InvalidOperationException(string.Format("Length mismatch for '_targetKeyFields' and '_sourceFields': {0} cf {1}.", _targetKeyFields.Length, _sourceFields.Length));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the view.
        /// </summary>
        /// <param name="member"></param>
        private void Initializing(ChildToParentEntityLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // get the fields...
            EntityField[] fields = link.GetLinkFields();
            if (fields == null)
            {
                throw new InvalidOperationException("fields is null.");
            }
            this.AllowNullSelection = false;
            foreach (EntityField field in fields)
            {
                if (field.IsNullable())
                {
                    this.AllowNullSelection = true;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates constraints for the given link.
        /// </summary>
        /// <param name="linkName"></param>
        /// <param name="filterOperator"></param>
        /// <param name="relatedEntity"></param>
        /// <returns></returns>
        private void AddConstraintsForLink(ChildToParentEntityLink link, SqlOperator filterOperator, IList relatedEntities)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            // check..
            if (filterOperator != SqlOperator.EqualTo && filterOperator != SqlOperator.NotEqualTo)
            {
                throw new NotSupportedException(string.Format(Cultures.System, "'{0}' is an invalid operator.  Only 'EqualTo' and 'NotEqualTo' are supported.", filterOperator));
            }

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

            // create...
            IEntityStorage storage = link.ParentEntityType.Storage;

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

            // get the key fields of the related type...
            EntityField[] foreignKeyFields = link.ParentEntityType.GetKeyFields();
            if (foreignKeyFields.Length == 0)
            {
                throw new InvalidOperationException(string.Format(Cultures.Exceptions, "Key fields on '{0}' was zero-length.", link.ParentEntityType));
            }

            // get teh fields in this...
            EntityField[] relatedFields = link.GetLinkFields();

            // compare...
            if (foreignKeyFields.Length != relatedFields.Length)
            {
                throw ExceptionHelper.CreateLengthMismatchException("foreignKeyFields", "relatedFields", foreignKeyFields.Length, relatedFields.Length);
            }

            // now loop...
            FilterConstraint lastTopConstraint = null;

            for (int entityIndex = 0; entityIndex < relatedEntities.Count; entityIndex++)
            {
                // get and check...
                object relatedEntity = relatedEntities[entityIndex];
                link.ParentEntityType.AssertIsOfType(relatedEntity);

                // create a top level constraint...
                FilterConstraint topConstraint = new FilterConstraint(this.Creator);
                Add(topConstraint);

                // set...
                if (lastTopConstraint != null)
                {
                    lastTopConstraint.CombineWithNext = SqlCombine.Or;
                }

                // new?
                if (storage.IsNew(relatedEntity) == false && storage.IsDeleted(relatedEntity, false) == false)
                {
                    // loop...
                    for (int index = 0; index < foreignKeyFields.Length; index++)
                    {
                        // get...
                        object foreignValue = storage.GetValue(relatedEntity, foreignKeyFields[index]);

                        // add a constraint...
                        topConstraint.ChildConstraints.Add(new EntityFieldFilterConstraint(this.Creator, relatedFields[index], filterOperator, foreignValue));
                    }
                }

                // next...
                lastTopConstraint = topConstraint;
            }
        }