예제 #1
0
        private static XElement ConstructComplexProperty(EdmProperty complexProperty, string columnNamePrefix, string csdlNamespace)
        {
            // don't add anything if the complex type associated with this property is empty.
            if (complexProperty == null ||
                complexProperty.TypeUsage == null ||
                !(complexProperty.TypeUsage.EdmType is ComplexType))
            {
                Debug.Fail("We should not have called ConstructComplexProperty on a property that is not a complex property");
                return(null);
            }

            var complexType = complexProperty.TypeUsage.EdmType as ComplexType;

            if (complexType != null)
            {
                if (complexType.Properties.Count == 0)
                {
                    return(null);
                }
            }

            var complexPropertyElement = new XElement(
                _msl + "ComplexProperty", new XAttribute("Name", complexProperty.Name),
                new XAttribute("TypeName", csdlNamespace + "." + complexProperty.TypeUsage.EdmType.Name));

            complexProperty.VisitComplexProperty(
                (namePrefix, nestedProperty) =>
            {
                if (nestedProperty.IsComplexProperty())
                {
                    complexPropertyElement.Add(
                        ConstructComplexProperty(nestedProperty, columnNamePrefix + "_" + nestedProperty.Name, csdlNamespace));
                }
                else
                {
                    complexPropertyElement.Add(
                        new XElement(
                            _msl + "ScalarProperty", new XAttribute("Name", nestedProperty.Name),
                            new XAttribute("ColumnName", columnNamePrefix + "_" + nestedProperty.Name)));
                }
            }, "_", false);

            if (complexPropertyElement.Nodes().Any())
            {
                return(complexPropertyElement);
            }
            return(null);
        }