예제 #1
0
 internal override ComplexPropertyMapping GetMapping(ComplexProperty complexProperty)
 {
     var value = GetSpecificMapping(complexProperty);
     if (value != null)
         return value;
     return EntityType.BaseType == null ? null : EntityType.BaseType.Mapping.GetMapping(complexProperty);
 }
 internal ListViewItem GetListViewItem(ComplexProperty complexProperty, out int index)
 {
     var value = (from lvi in VisualTreeHelperUtil.GetControlsDecendant<ListViewItem>(propertiesListView)
                  let uiRelatedProperty = lvi.Content as UIRelatedProperty
                  where uiRelatedProperty != null
                  select new { ListViewItem = lvi, UIRelatedProperty = uiRelatedProperty }).Select((lvi, i) => new { ListViewItem = lvi, Index = i }).First(lvi => lvi.ListViewItem.UIRelatedProperty.BusinessInstance == complexProperty);
     index = value.Index;
     return value.ListViewItem.ListViewItem;
 }
 public ComplexPropertyMapping(ComplexProperty complexProperty, MappingBase mapping, ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.EntityType.EntityType table)
 {
     ComplexProperty = complexProperty;
     Mapping = mapping;
     Table = table;
 }
예제 #4
0
 private bool RemoveSSDLTableToComplexProperty(ComplexProperty complexProperty, MappingBase mapping, SSDL.EntityType.EntityType ssdlTable)
 {
     bool deleteAll = true;
     foreach (var prop in mapping.Mapping.Keys.ToList())
     {
         var propMapping = mapping.Mapping[prop];
         if (propMapping.Count == 1)
             mapping.RemoveMapping(prop);
         else
         {
             propMapping.Remove(ssdlTable);
             deleteAll = false;
         }
     }
     foreach (var complexProp in mapping.ComplexMapping.Keys.ToList())
         if (RemoveSSDLTableToComplexProperty(complexProp, mapping.ComplexMapping[complexProp], ssdlTable))
             mapping.ComplexMapping.Remove(complexProp);
         else
             deleteAll = false;
     return deleteAll;
 }
예제 #5
0
 private bool TryToAddSSDLColumnToComplexProperty(ComplexProperty complexProperty, Func<MappingBase> mapping, SSDL.Property.Property column)
 {
     var prop = complexProperty.ComplexType.ScalarProperties.FirstOrDefault(p => p.Name == column.Name);
     if (prop != null)
     {
         mapping().AddMapping(prop, column);
         return true;
     }
     foreach (var complexProp in complexProperty.ComplexType.ComplexProperties)
         if (TryToAddSSDLColumnToComplexProperty(complexProp, () =>
             {
                 var complexMapping = mapping().ComplexMapping;
                 if (complexMapping.ContainsKey(complexProp))
                     return complexMapping[complexProp];
                 var complexPropMapping = new ComplexPropertyMapping(EntityType, complexProp);
                 complexMapping.Add(complexProp, complexPropMapping);
                 return complexPropMapping;
             }, column))
             return true;
     return false;
 }
예제 #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);
                }
            }
        }
 public ComplexPropertyMapping(CSDL.Type.EntityType entityType, ComplexProperty complexProperty)
     : base(entityType)
 {
     ComplexProperty = complexProperty;
 }