private FunctionImportReturnTypeStructuralTypeColumn GetRename(StructuralType typeForRename)
        {
            FunctionImportReturnTypeStructuralTypeColumn ofTypecolumn = _columnListForType.FirstOrDefault(t => t.Type == typeForRename);

            if (null != ofTypecolumn)
            {
                return(ofTypecolumn);
            }

            // if there are duplicate istypeof mapping defined rename for the same column, the last one wins
            FunctionImportReturnTypeStructuralTypeColumn isOfTypeColumn = _columnListForIsTypeOfType.Where(t => t.Type == typeForRename).LastOrDefault();

            if (null != isOfTypeColumn)
            {
                return(isOfTypeColumn);
            }
            else
            {
                // find out all the tyes that is isparent type of this lookup type
                IEnumerable <FunctionImportReturnTypeStructuralTypeColumn> nodesInBaseHierachy =
                    _columnListForIsTypeOfType.Where(t => t.Type.IsAssignableFrom(typeForRename));

                if (nodesInBaseHierachy.Count() == 0)
                {
                    // non of its parent is renamed, so it will take the default one
                    return(new FunctionImportReturnTypeStructuralTypeColumn(this._defaultMemberName, typeForRename, false, null));
                }
                else
                {
                    // we will guarantee that there will be some mapping for us on this column
                    // find out which one is lowest on the link
                    return(GetLowestParentInHierachy(nodesInBaseHierachy));
                }
            }
        }
        internal void AddRename(FunctionImportReturnTypeStructuralTypeColumn renamedColumn)
        {
            EntityUtil.CheckArgumentNull(renamedColumn, "renamedColumn");

            if (!renamedColumn.IsTypeOf)
            {
                // add to collection if the mapping is for specific type
                this._columnListForType.Add(renamedColumn);
            }
            else
            {
                _columnListForIsTypeOfType.Add(renamedColumn);
            }
        }
        private FunctionImportReturnTypeStructuralTypeColumn GetLowestParentInHierachy(IEnumerable <FunctionImportReturnTypeStructuralTypeColumn> nodesInHierachy)
        {
            FunctionImportReturnTypeStructuralTypeColumn lowestParent = null;

            foreach (var node in nodesInHierachy)
            {
                if (lowestParent == null)
                {
                    lowestParent = node;
                }
                else if (lowestParent.Type.IsAssignableFrom(node.Type))
                {
                    lowestParent = node;
                }
            }
            Debug.Assert(null != lowestParent, "We should have the lowest parent");
            return(lowestParent);
        }
        internal void AddRename(FunctionImportReturnTypeStructuralTypeColumn renamedColumn)
        {
            EntityUtil.CheckArgumentNull(renamedColumn, "renamedColumn");

            if (!renamedColumn.IsTypeOf)
            {
                // add to collection if the mapping is for specific type
                this._columnListForType.Add(renamedColumn);
            }
            else
            {
                _columnListForIsTypeOfType.Add(renamedColumn);
            }
        }
        internal void AddRename(FunctionImportReturnTypeStructuralTypeColumn renamedColumn)
        {
            //Contract.Requires(renamedColumn != null);

            if (!renamedColumn.IsTypeOf)
            {
                // add to collection if the mapping is for specific type
                _columnListForType.Add(renamedColumn);
            }
            else
            {
                _columnListForIsTypeOfType.Add(renamedColumn);
            }
        }