Beispiel #1
0
        /// <summary>
        /// Gets the short name of the entity for the context
        /// </summary>
        /// <param name="context">The context object which directly or indirectly points to an entry</param>
        /// <returns>The short name of entity</returns>
        public static string GetEntityName(ServiceContext context)
        {
            string entityName = context.EntityTypeShortName;

            if (string.IsNullOrEmpty(entityName))
            {
                var     edmxHelper   = new EdmxHelper(XElement.Parse(context.MetadataDocument));
                var     segments     = ResourcePathHelper.GetPathSegments(context);
                var     segsToEntity = GetEntryUriSegments(segments.Take(segments.Count() - 1), edmxHelper);
                UriType uriType;
                var     target = edmxHelper.GetTargetType(segsToEntity, out uriType);
                entityName = ((EntityType)target).Name;
            }
            return(entityName);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the segments pointing to an entry based
        /// </summary>
        /// <param name="segments">The segments pointing to derived resources of the entry</param>
        /// <param name="edmxHelper">The EdmxHelper instance</param>
        /// <returns>The segments pointing to the entry</returns>
        public static IEnumerable <string> GetEntryUriSegments(IEnumerable <string> segments, EdmxHelper edmxHelper)
        {
            if (!segments.Any())
            {
                return(segments);
            }

            UriType uriType;
            var     target = edmxHelper.GetTargetType(segments, out uriType);

            if (uriType == UriType.URI2)
            {
                return(segments);
            }

            return(GetEntryUriSegments(segments.Take(segments.Count() - 1), edmxHelper));
        }