Example #1
0
        /// <summary>
        /// Checks whether the entity type definition has any property mapping
        /// </summary>
        /// <param name="meta">The metadata document</param>
        /// <param name="entityType">The entity type</param>
        /// <returns>flag of proerty being mapped</returns>
        public static bool HasPropertyMapping(XElement meta, string entityType)
        {
            if (meta == null)
            {
                throw new ArgumentNullException("meta");
            }

            if (string.IsNullOrEmpty(entityType))
            {
                throw new ArgumentException("parameter should not be null or empty", "entityType");
            }

            const string tmplXPath2EntityType = @"//*[local-name()='EntityType' and @Name = '{0}']";
            const string xPath2Property       = @"./*[local-name()='Property' and @m:FC_KeepInContent='false']";

            string typeShortName = ResourcePathHelper.GetBaseName(entityType);

            string xPath2EntityType = string.Format(tmplXPath2EntityType, typeShortName);
            var    nodeEntityType   = meta.XPathSelectElement(xPath2EntityType, ODataNamespaceManager.Instance);
            var    nodeProperty     = nodeEntityType.XPathSelectElement(xPath2Property, ODataNamespaceManager.Instance);

            if (nodeProperty != null)
            {
                return(true);
            }
            else
            {
                string baseType = nodeEntityType.GetAttributeValue("BaseType");
                if (baseType == null)
                {
                    return(false);
                }
                else
                {
                    return(HasPropertyMapping(meta, baseType));
                }
            }
        }