public AssociationMapping(Association association)
 {
     if (association == null)
         throw new ArgumentNullException();
     Association = association;
     InitializeComponent();
 }
Пример #2
0
 public void BindAssociation(Association association)
 {
     Association = association;
     EntityType = null;
     if (association == null)
     {
         Visibility = Visibility.Collapsed;
         return;
     }
     nameTextBlock.Text = association.Name;
     Clear();
     Visibility = Visibility.Visible;
     var associationMapping = new AssociationMapping(association) { Tables = EDM.SSDLContainer.EntityTypes };
     associationMapping.TableComboBoxValue.ComboSelectedValue = association.Mapping.SSDLTableMapped;
     stackPanel.Children.Add(associationMapping);
 }
Пример #3
0
 public void BindEntityType(EntityType entityType)
 {
     EntityType = entityType;
     Association = null;
     if (entityType == null)
     {
         Visibility = Visibility.Collapsed;
         return;
     }
     nameTextBlock.Text = entityType.Name;
     Clear();
     Visibility = Visibility.Visible;
     foreach (var tableMapped in entityType.Mapping.MappedSSDLTables.ToList())
     {
         var tableMapping = AddNewEntityTableMapping();
         tableMapping.Tables = PossiblesTables.Union(new[] { tableMapped });
         tableMapping.TableComboBoxValue.ComboSelectedValue = tableMapped;
     }
 }
Пример #4
0
        public Association.Association AddAssociation(string associationName, string navigationProperty1Name, EntityType navigationProperty1EnityType, Cardinality navigationProperty1Cardinality, string navigationProperty2Name, EntityType navigationProperty2EnityType, Cardinality navigationProperty2Cardinality)
        {
            var association = new Association.Association {
                Container = this, Name = associationName
            };
            var navigationProperty1 = new NavigationProperty(association)
            {
                Name = navigationProperty1Name, Cardinality = navigationProperty1Cardinality
            };

            navigationProperty1EnityType.NavigationProperties.Add(navigationProperty1);
            association.PropertyEnd1 = navigationProperty1;
            var navigationProperty2 = new NavigationProperty(association)
            {
                Name = navigationProperty2Name, Cardinality = navigationProperty2Cardinality
            };

            navigationProperty2EnityType.NavigationProperties.Add(navigationProperty2);
            association.PropertyEnd2 = navigationProperty2;
            return(association);
        }
Пример #5
0
 public Association.Association AddAssociation(string associationName, string navigationProperty1Name, EntityType navigationProperty1EnityType, Cardinality navigationProperty1Cardinality, string navigationProperty2Name, EntityType navigationProperty2EnityType, Cardinality navigationProperty2Cardinality)
 {
     var association = new Association.Association { Container = this, Name = associationName };
     var navigationProperty1 = new NavigationProperty(association) { Name = navigationProperty1Name, Cardinality = navigationProperty1Cardinality };
     navigationProperty1EnityType.NavigationProperties.Add(navigationProperty1);
     association.PropertyEnd1 = navigationProperty1;
     var navigationProperty2 = new NavigationProperty(association) { Name = navigationProperty2Name, Cardinality = navigationProperty2Cardinality };
     navigationProperty2EnityType.NavigationProperties.Add(navigationProperty2);
     association.PropertyEnd2 = navigationProperty2;
     return association;
 }
Пример #6
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);
                }
            }
        }