예제 #1
0
        /// <summary>
        /// Gets sub item of the specified EntityContainer instance by the name 
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(EntityContainer container, string name)
        {
            ODataUriItem result = null;

            EntitySet entitySet;
            bool isEntitySet = container.TryGetEntitySetByName(name, false, out entitySet);
            if (isEntitySet)
            {
                return new ODataUriItem(entitySet, UriType.URI1);
            }
            else
            {
                var fs = container.FunctionImports.Where(x => x.Name.Equals(name, StringComparison.Ordinal));
                if (fs.Any())
                {
                    EdmFunction func = fs.First();
                    var retVal = func.ReturnParameter;
                    var retType = retVal.TypeUsage.EdmType;
                    UriType retUriType = GetUriTypeOfFuncReturn(retType);
                    if (retUriType == UriType.URI11 || retUriType == UriType.URI13 || retUriType == UriType.URI_CollEt)
                    {
                        result = new ODataUriItem(((CollectionType)retType).TypeUsage.EdmType, retUriType);
                    }
                    else
                    {
                        result = new ODataUriItem(retType, retUriType);
                    }
                }
            }

            return result;
        }