public ComplexPropertiesMapping(TypeBase type, MappingBase mapping, ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.EntityType.EntityType table)
 {
     Type = type;
     Mapping = mapping;
     Table = table;
     TPC = true;
 }
 internal void AddToType(TypeBase type)
 {
     if (type != null)
     {
         EntityType = type;
         GetPropertyCollection(type).Add(this);
     }
 }
Beispiel #3
0
        private static IEnumerable<XElement> MappingComplexProperties(TypeBase type, MappingBase mapping, EDMObjects.SSDL.EntityType.EntityType table, string entityContainerNamespace)
        {
            foreach (ComplexProperty complexProperty in type.AllComplexProperties)
            {
                ComplexPropertyMapping complexPropertyMapping = mapping.GetEntityTypeSpecificComplexPropertyMapping(complexProperty);

                if (complexPropertyMapping != null)
                {
                    XElement complexPropertyElement = new XElement(mslNamespace + "ComplexProperty",
                        new XAttribute("Name", complexProperty.Name));

                    IEnumerable<PropertyMapping> scalarMappings = complexPropertyMapping.GetSpecificMappingForTable(table);

                    foreach (PropertyMapping scalarMapping in scalarMappings)
                    {
                        complexPropertyElement.AddElement(new XElement(mslNamespace + "ScalarProperty",
                            new XAttribute("Name", scalarMapping.Property.Name),
                            new XAttribute("ColumnName", scalarMapping.Column.Name)));
                    }

                    foreach (ComplexProperty subComplexProperty in complexProperty.ComplexType.ComplexProperties)
                    {
                        complexPropertyElement.Add(MappingComplexProperties(complexProperty.ComplexType, complexPropertyMapping, table, entityContainerNamespace));
                    }

                    yield return complexPropertyElement;
                }
            }
        }
Beispiel #4
0
 private static void SetCUDFunctionParametersScalarMapping(TypeBase entityType, XElement functionMappingElement, CUDFunctionParametersMapping cudFunctionParametersMapping, ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.Function.Function ssdlFunction)
 {
     foreach (var scalarPropertyElement in functionMappingElement.Elements(XName.Get("ScalarProperty", mslNamespace.NamespaceName)))
     {
         var scalarProperty = entityType.AllScalarProperties.GetByName(scalarPropertyElement.Attribute("Name").Value);
         var parameter = ssdlFunction.Parameters.GetByName(scalarPropertyElement.Attribute("ParameterName").Value);
         var versionAttribute = scalarPropertyElement.Attribute("Version");
         var functionParameterMapping = new FunctionParameterMapping { SSDLFunctionParameter = parameter };
         if (versionAttribute != null)
             functionParameterMapping.Version = versionAttribute.Value.ToLower() == "current" ? FunctionParameterVersion.Current : FunctionParameterVersion.Original;
         cudFunctionParametersMapping[scalarProperty] = functionParameterMapping;
     }
 }
Beispiel #5
0
 private static void SetCUDFunctionParametersMapping(TypeBase entityType, XElement functionMappingElement, EntityTypeCUDFunctionParametersMapping cudFunctionParametersMapping, ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.Function.Function ssdlFunction)
 {
     SetCUDFunctionParametersScalarMapping(entityType, functionMappingElement, cudFunctionParametersMapping, ssdlFunction);
     foreach (var complexPropertyElement in functionMappingElement.Elements(XName.Get("ComplexProperty", mslNamespace.NamespaceName)))
     {
         var cudFunctionComplexPropertyParametersMapping = new EntityTypeCUDFunctionParametersMapping();
         var complexProperty = entityType.AllComplexProperties.GetByName(complexPropertyElement.Attribute("Name").Value);
         cudFunctionParametersMapping.ComplexPropertiesMapping.Add(new KeyValuePair<ComplexProperty, EntityTypeCUDFunctionParametersMapping>(complexProperty, cudFunctionComplexPropertyParametersMapping));
         SetCUDFunctionParametersMapping(complexProperty.ComplexType, complexPropertyElement, cudFunctionComplexPropertyParametersMapping, ssdlFunction);
     }
 }
Beispiel #6
0
 private static void MapComplexProperties(XElement complexMappingParentElement, MappingBase complexMappingOwner, TypeBase type, ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.EntityType.EntityType table)
 {
     foreach (var complexPropertyElement in complexMappingParentElement.Elements(XName.Get("ComplexProperty", mslNamespace.NamespaceName)))
     {
         var complexProperty = type.AllComplexProperties.GetByName(complexPropertyElement.Attribute("Name").Value);
         var complexPropertyMapping = complexMappingOwner[complexProperty];
         foreach (var scalarPropertyElement in complexPropertyElement.Elements(XName.Get("ScalarProperty", mslNamespace.NamespaceName)))
         {
             var scalarProperty = complexProperty.ComplexType.AllScalarProperties.GetByName(scalarPropertyElement.Attribute("Name").Value);
             var column = table.Properties.First(c => c.Name == scalarPropertyElement.Attribute("ColumnName").Value);
             complexPropertyMapping[scalarProperty, table] = column;
         }
         MapComplexProperties(complexPropertyElement, complexPropertyMapping, complexProperty.ComplexType, table);
     }
 }
Beispiel #7
0
        private static void ReadCSDLType(XElement schemaElement, XElement entityTypeElement, CSDLContainer container, TypeBase baseType)
        {
            if (baseType.Name == null)
                baseType.Name = entityTypeElement.Attribute("Name").Value;
            SetVisibilityValueFromAttribute(entityTypeElement, "TypeAccess", typeAccess => baseType.Visibility = typeAccess);

            foreach (var propertyElement in entityTypeElement.Elements(XName.Get("Property", csdlNamespace.NamespaceName)))
            {
                var name = propertyElement.Attribute("Name").Value;
                var keyElement = entityTypeElement.Element(XName.Get("Key", csdlNamespace.NamespaceName));
                var propertyType = GetScalarPropertyTypeFromAttribute(propertyElement);
                PropertyBase property;
                if (propertyType == null)
                {
                    property = new ComplexProperty(GetName(propertyElement.Attribute("Type").Value)) { Name = name };
                    baseType.ComplexProperties.Add((ComplexProperty)property);
                }
                else
                {
                    property = new ScalarProperty() { Name = name, IsKey = keyElement != null && keyElement.Elements(XName.Get("PropertyRef", csdlNamespace.NamespaceName)).Where(pr => pr.Attribute("Name").Value == name).Any(), Type = propertyType.Value };
                    var scalarProp = (ScalarProperty)property;
                    SetBoolValueFromAttribute(propertyElement, "Nullable", nullable => scalarProp.Nullable = nullable);
                    SetVisibilityValueFromAttribute(propertyElement, "SetterAccess", setterAccess => scalarProp.SetVisibility = setterAccess);
                    SetIntValueFromAttribute(propertyElement, "MaxLength", maxLength => scalarProp.MaxLength = maxLength);
                    SetBoolValueFromAttribute(propertyElement, "Unicode", unicode => scalarProp.Unicode = unicode);
                    SetBoolValueFromAttribute(propertyElement, "FixedLength", fixedLength => scalarProp.FixedLength = fixedLength);
                    SetIntValueFromAttribute(propertyElement, "Precision", precision => scalarProp.Precision = precision);
                    SetIntValueFromAttribute(propertyElement, "Scale", scale => scalarProp.Scale = scale);
                    SetStringValueFromAttribute(propertyElement, "ConcurrencyMode", concurrencyMode => scalarProp.ConcurrencyMode = ConcurrencyMode.None);
                    SetStringValueFromAttribute(propertyElement, "DefaultValue", defaultValue => scalarProp.DefaultValue = defaultValue);
                    SetStringValueFromAttribute(propertyElement, "Collation", collation => scalarProp.Collation = collation);
                    baseType.ScalarProperties.Add(scalarProp);
                }
                SetVisibilityValueFromAttribute(propertyElement, "GetterAccess", getterAccess => property.GetVisibility = getterAccess);
            }
            var entityType = baseType as EntityType;
            if (entityType != null)
            {
                foreach (var navigationPropertyElement in entityTypeElement.Elements(XName.Get("NavigationProperty", csdlNamespace.NamespaceName)))
                {
                    var navigationPropertyname = navigationPropertyElement.Attribute("Name").Value;
                    var associationName = GetName(navigationPropertyElement.Attribute("Relationship").Value);
                    var associationElement = schemaElement.Elements(XName.Get("Association", csdlNamespace.NamespaceName)).First(ae => ae.Attribute("Name").Value == associationName);
                    Association association = container.AssociationsCreated.GetByName(associationName);
                    bool associationExisting = association != null;
                    if (!associationExisting)
                    {
                        association = new Association { Name = associationName };
                        container.AssociationsCreated.Add(association);
                    }
                    var navigationProperty = new NavigationProperty(association) { Name = navigationPropertyname };
                    var roleName = navigationPropertyElement.Attribute("FromRole").Value;
                    SetCardinalityValueFromAttribute(associationElement.Elements(XName.Get("End", csdlNamespace.NamespaceName)).First(ee => ee.Attribute("Role").Value == roleName), cardinality => navigationProperty.Cardinality = cardinality);
                    SetVisibilityValueFromAttribute(navigationPropertyElement, "GetterAccess", visibility => navigationProperty.GetVisibility = visibility);
                    SetVisibilityValueFromAttribute(navigationPropertyElement, "SetterAccess", visibility => navigationProperty.SetVisibility = visibility);
                    if (associationExisting)
                    {
                        association.PropertyEnd2 = navigationProperty;
                        association.PropertyEnd2Role = roleName;
                    }
                    else
                    {
                        association.PropertyEnd1 = navigationProperty;
                        association.PropertyEnd1Role = roleName;
                        string toRoleName = navigationPropertyElement.Attribute("ToRole").Value;
                        NavigationProperty fakeNavigationProperty = new NavigationProperty(association) { Name = roleName, Generate = false };
                        SetCardinalityValueFromAttribute(associationElement.Elements(XName.Get("End", csdlNamespace.NamespaceName)).First(ee => ee.Attribute("Role").Value == toRoleName), cardinality => fakeNavigationProperty.Cardinality = cardinality);
                        association.PropertyEnd2 = fakeNavigationProperty;
                        association.PropertyEnd2Role = toRoleName;
                    }
                    var referentialConstraintElement = associationElement.Element(XName.Get("ReferentialConstraint", csdlNamespace.NamespaceName));
                    if (referentialConstraintElement != null)
                    {
                        var referentialConstraintRoleElement = referentialConstraintElement.Elements().First(rce => rce.Attribute("Role").Value == roleName);
                        var scalarProperties = referentialConstraintRoleElement.Elements(XName.Get("PropertyRef", csdlNamespace.NamespaceName)).Select(e => entityType.AllScalarProperties.First(sp => sp.Name == e.Attribute("Name").Value));
                        switch (referentialConstraintRoleElement.Name.LocalName)
                        {
                            case "Principal":
                                association.PrincipalRole = roleName;
                                association.PrincipalProperties = scalarProperties;
                                break;
                            case "Dependent":
                                association.DependentRole = roleName;
                                association.DependentProperties = scalarProperties;
                                break;
                            default:
                                throw new NotImplementedException();
                        }
                    }
                    entityType.NavigationProperties.Add(navigationProperty);
                }
            }
        }
Beispiel #8
0
 private static IEnumerable<XElement> WriteComplexProperties(TypeBase type, string csdlAlias)
 {
     foreach (ComplexProperty complexProperty in type.ComplexProperties)
     {
         yield return new XElement(csdlNamespace + "Property")
             .AddAttribute("Name", complexProperty.Name)
             .AddAttribute("Type", string.Concat(csdlAlias, complexProperty.ComplexType.Name))
             .AddAttribute("Nullable", false);
             //.AddAttribute(csdlCodeGenerationNamespace, "GetterAccess", complexProperty.GetVisibility);  // Not available in EF 4.0
     }
 }
Beispiel #9
0
 private static IEnumerable<XElement> WriteScalarProperties(TypeBase type)
 {
     foreach (ScalarProperty scalarProperty in type.ScalarProperties)
     {
         yield return new XElement(csdlNamespace + "Property")
             .AddAttribute("Name", scalarProperty.Name)
             .AddAttribute("Type", scalarProperty.Type)
             .AddAttribute("Collation", scalarProperty.Collation)
             .AddAttribute("ConcurrencyMode", scalarProperty.ConcurrencyMode)
             .AddAttribute("DefaultValue", scalarProperty.DefaultValue)
             .AddAttribute("FixedLength", scalarProperty.FixedLength)
             //.AddAttribute(csdlCodeGenerationNamespace, "GetterAccess", scalarProperty.GetVisibility)  // Not available in EF 4.0
             .AddAttribute("MaxLength", scalarProperty.MaxLength)
             .AddAttribute("Nullable", scalarProperty.Nullable)
             .AddAttribute("Precision", scalarProperty.Precision)
             .AddAttribute("Scale", scalarProperty.Scale)
             //.AddAttribute(csdlCodeGenerationNamespace, "SetterAccess", scalarProperty.SetVisibility)  // Not available in EF 4.0
             .AddAttribute("Unicode", scalarProperty.Unicode);
     }
 }