private void RemoveNavigationPropertyMappingListeners(NavigationProperty navigationProperty) { }
public string GetRoleName(NavigationProperty navigationProperty) { if (navigationProperty == PropertyEnd1) return PropertyEnd1Role; if (navigationProperty == PropertyEnd2) return PropertyEnd2Role; throw new InvalidOperationException(); }
private void RemoveNotNullCondition(NavigationProperty navigationProperty) { foreach (var column in navigationProperty.Mapping.Select(pm => pm.Column)) RemoveNotNullCondition(column); RemoveNavigationPropertyMappingListeners(navigationProperty); }
private void AddNavigationPropertyMappingListeners(NavigationProperty navigationProperty) { navigationProperty.Mapping.Added += (p, c) => AddNotNullCondition(c); navigationProperty.Mapping.Changed += (p, oldC, newC) => { RemoveNotNullCondition(oldC); AddNotNullCondition(newC); }; navigationProperty.Mapping.Removed += (p, c) => RemoveNotNullCondition(c); }
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; }
private void AddNotNullCondition(NavigationProperty navigationProperty) { foreach (var column in navigationProperty.Mapping.Select(pm => pm.Column)) if (!Mapping.ConditionsMapping.Any(ccm => ccm.Column == column && ccm.Operator == ConditionOperator.IsNotNull)) AddNotNullCondition(column); AddNavigationPropertyMappingListeners(navigationProperty); }
private void _navigationProperties_ItemRemoved(NavigationProperty navigationProperty) { _navigationProperties.ItemRemoved -= _navigationProperties_ItemRemoved; var navigationProperty2 = navigationProperty.Association.PropertiesEnd.First(pe => pe != navigationProperty); if (!navigationProperty2.IsDeleted) navigationProperty2.EntityType.NavigationProperties.Remove(navigationProperty2); _navigationProperties.ItemRemoved += _navigationProperties_ItemRemoved; }
internal ListViewItem GetListViewItem(NavigationProperty navigationProperty, out int index) { foreach (ListViewItem lvia in VisualTreeHelperUtil.GetControlsDecendant<ListViewItem>(propertiesListView)) { lvia.ToString(); } 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 == navigationProperty); index = value.Index; // +navigationProperty.EntityType.ComplexProperties.Count; return value.ListViewItem.ListViewItem; }
internal void DrawAssociation(TypeBaseDesigner otherTypeDesigner, NavigationProperty navigationProperty) { var csdlAssociation = navigationProperty.Association; int otherTypeDesignerItemIndex; var otherNavigationProperty = csdlAssociation.PropertiesEnd.First(np => np != navigationProperty); var otherListViewItem = otherTypeDesigner.GetListViewItem(otherNavigationProperty, out otherTypeDesignerItemIndex); int typeDesignerItemIndex; var typeDesignerListViewItem = GetListViewItem(navigationProperty, out typeDesignerItemIndex); ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Relations.Association association; if (csdlAssociation.PropertyEnd1 == navigationProperty) association = new ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Relations.Association(csdlAssociation, Designer, this, otherTypeDesigner, typeDesignerListViewItem, otherListViewItem, typeDesignerItemIndex, otherTypeDesignerItemIndex); else association = new ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Relations.Association(csdlAssociation, Designer, otherTypeDesigner, this, otherListViewItem, typeDesignerListViewItem, otherTypeDesignerItemIndex, typeDesignerItemIndex); var relationContener = new RelationContener(association); Designer.Children.Add(relationContener); relationContener.SetBinding(Canvas.LeftProperty, new Binding { Source = association, Path = new PropertyPath("CanvasLeft") }); relationContener.SetBinding(Canvas.TopProperty, new Binding { Source = association, Path = new PropertyPath("CanvasTop") }); AddRelationContenerByRelatedProperty(UIType.Properties[navigationProperty], relationContener); otherTypeDesigner.AddRelationContenerByRelatedProperty(otherTypeDesigner.UIType.Properties[otherNavigationProperty], relationContener); NotifyCollectionChangedEventHandler mappingCollectionChanged = delegate { VisualTreeHelperUtil.GetControlsDecendant<EditableTextBlock>(otherListViewItem).First().GetBindingExpression(EditableTextBlock.OpacityProperty).UpdateTarget(); VisualTreeHelperUtil.GetControlsDecendant<EditableTextBlock>(typeDesignerListViewItem).First().GetBindingExpression(EditableTextBlock.OpacityProperty).UpdateTarget(); }; csdlAssociation.PropertyEnd1.Mapping.CollectionChanged += mappingCollectionChanged; csdlAssociation.PropertyEnd2.Mapping.CollectionChanged += mappingCollectionChanged; }
public AssociationPropertiesMapping(NavigationProperty navigationProperty, EntityType table) : base(navigationProperty.EntityType, table) { NavigationProperty = navigationProperty; }
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); } } }