Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets segments of URI relative path from ServiceContext instance
        /// </summary>
        /// <param name="context">The ServiceContext instance</param>
        /// <returns>The segments of relative path</returns>
        public static IEnumerable <string> GetPathSegments(ServiceContext context)
        {
            var path = context.DestinationBasePath.Substring(context.ServiceBaseUri.AbsoluteUri.Length);

            return(ResourcePathHelper.GetPathSegments(path));
        }