protected override Dictionary<SSDL.EntityType.EntityType, SSDL.Property.Property> GetBaseMapping(ScalarProperty scalarProperty) { var value = base.GetBaseMapping(scalarProperty); if (value != null) return value; if (EntityType.BaseType != null) return EntityType.BaseType.Mapping[scalarProperty]; return null; }
public PropertyMapping(ScalarProperty property, IMapping mapping, EntityType table) { if (property == null || mapping == null) throw new ArgumentNullException(); Property = property; Mapping = mapping; Table = table; if (BusinessPropertyMapping != null) _column = BusinessPropertyMapping.Column; }
protected override void OnScalarPropertyRemoved(ScalarProperty scalarProperty) { base.OnScalarPropertyRemoved(scalarProperty); Mapping.RemoveMapping(scalarProperty); }
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); } } }
protected virtual void OnScalarPropertyRemoved(ScalarProperty scalarProperty) { }