Exemplo n.º 1
0
        /// <summary>
        /// Gets the association name of a navigation node.
        /// </summary>
        /// <param name="navigationNode">Novigation node from where to get the association name.</param>
        /// <returns></returns>
        public static string GetNavigationAssociationName(XElement navigationNode)
        {
            string associationName = navigationNode.Attribute(
                EdmxNodeAttributes.NavigationProperty_Relationship).Value;

            return(EdmxHelper.GetNameWithoutNamespace(associationName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the Class Base Type of an EntityType node.
        /// </summary>
        /// <param name="entityNode">EntityType node to get the Class Base Type.</param>
        /// <returns></returns>
        public static string GetEntityBaseType(XElement entityNode)
        {
            string entityBaseType = null;

            if (entityNode.Attribute(EdmxNodeAttributes.EntityType_BaseType) != null)
            {
                entityBaseType = entityNode.Attribute(EdmxNodeAttributes.EntityType_BaseType).Value;

                entityBaseType = EdmxHelper.GetNameWithoutNamespace(entityBaseType);
            }

            return(entityBaseType);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the CSharp Type from a EDMX Property.
        /// </summary>
        /// <param name="propertyNode">Type attribute.</param>
        /// <param name="entityOwnerName">Entity owner name.</param>
        /// <returns></returns>
        public static string GetTypeFromEDMXProperty(XElement propertyNode, string entityOwnerName)
        {
            // Get the Type attribute
            XAttribute typeAttribute = propertyNode.Attribute(EdmxNodeAttributes.Property_Type);

            // Check Type attribute exists
            if (typeAttribute == null)
            {
                string propertyName = propertyNode.Attribute(EdmxNodeAttributes.Property_Name).Value;

                throw new ApplicationException(string.Format(Resources.Error_PropertyTypeAttributeMissing,
                                                             entityOwnerName, propertyName));
            }

            // Get the Type value
            string edmxTypeValue = propertyNode.Attribute(EdmxNodeAttributes.Property_Type).Value;

            // Check Type value is not empty
            if (string.IsNullOrWhiteSpace(edmxTypeValue))
            {
                string propertyName = propertyNode.Attribute(EdmxNodeAttributes.Property_Name).Value;

                throw new ApplicationException(string.Format(Resources.Error_PropertyTypeAttributeMissing,
                                                             entityOwnerName, propertyName));
            }

            // Check if it is Nullable
            bool       isNullable        = true;
            XAttribute nullableAttribute = propertyNode.Attribute(EdmxNodeAttributes.Property_Nullable);

            if (nullableAttribute != null)
            {
                isNullable = (nullableAttribute.Value == Resources.XmlBoolTrue);
            }

            // Variables
            string outputType = null;
            bool   outputTypeAdmitsNullable = false;

            // Check if it is a supported type and we got the mapping for it
            if (PropertyHelper.EdmxCSharpMapping.ContainsKey(edmxTypeValue))
            {
                // Do the mapping between the EDMX type and the C# type
                outputType = PropertyHelper.EdmxCSharpMapping[edmxTypeValue].Name;
                outputTypeAdmitsNullable = PropertyHelper.EdmxCSharpMapping[edmxTypeValue].AllowsNullable;
            }
            else
            {
                // Get type name without namespce to check if it is a type defined in the EDMX (ComplexType, EnumType)
                string edmxTypeName = EdmxHelper.GetNameWithoutNamespace(edmxTypeValue);

                // Check if it is a complex type
                DTOEntity complexTypeDTO = PropertyHelper.ComplexTypes.FirstOrDefault(ct => ct.Name == edmxTypeName);

                if (complexTypeDTO != null)
                {
                    // It is a ComplexType
                    outputType = complexTypeDTO.NameDTO;
                    outputTypeAdmitsNullable = true;
                }
                else if (PropertyHelper.EnumTypes.Exists(e => e.Name == edmxTypeName))
                {
                    // It is an EnumType
                    outputType = edmxTypeName;
                    outputTypeAdmitsNullable = true;
                }
                else
                {
                    // Not a supported Type neither a Type defined in the EDMX
                    // Use object type and notify the user
                    outputType = Resources.CSharpTypeObject;
                    outputTypeAdmitsNullable = true;

                    string propertyName = propertyNode.Attribute(EdmxNodeAttributes.Property_Name).Value;

                    // TODO: ffernandez, indicate Project-ProjectItem-Line-Column
                    VisualStudioHelper.AddToErrorList(TaskErrorCategory.Warning,
                                                      string.Format(Resources.Warning_NotSupportedEDMXPropertyType, entityOwnerName, propertyName, edmxTypeValue),
                                                      null, null, null, null);
                }
            }

            // Check if it is Nullable and the Type admits Nullable Types
            if (isNullable && outputTypeAdmitsNullable)
            {
                outputType = string.Format(Resources.CSharpTypeNullableT, outputType);
            }

            return(outputType);
        }