Exemplo n.º 1
0
        /// <summary>
        /// Performs a deep copy of the specified <see cref="NavigationProperty"/>.
        /// </summary>
        /// <param name="navigationProperty">The <see cref="NavigationProperty"/> to deep copy.</param>
        /// <returns>A deep copy of the <see cref="NavigationProperty"/>.</returns>
        private static NavigationProperty Clone(this NavigationProperty navigationProperty)
        {
            var clone = new NavigationProperty(
                navigationProperty.Name,
                navigationProperty.Association.Name,
                navigationProperty.FromAssociationEnd.RoleName,
                navigationProperty.ToAssociationEnd.RoleName);

            CopyAnnotations(clone, navigationProperty.Annotations);

            return(clone);
        }
 /// <summary>
 /// Adds a navigation property to the given type declaration based on the given metadata
 /// If the multiplicity is One, then we add a clr property which fires property change notifications
 /// </summary>
 /// <param name="navigationProperty">The property's metadata</param>
 /// <param name="parentClass">The type declaration</param>
 protected override void DeclareNavigationProperty(NavigationProperty navigationProperty, CodeTypeDeclaration parentClass)
 {
     if (navigationProperty.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
     {
         base.DeclareNavigationProperty(navigationProperty, parentClass);
     }
     else
     {
         this.AddPropertyWithChangeNotification(parentClass, this.GetPropertyType(navigationProperty, CodeGenerationTypeUsage.Declaration), navigationProperty.Name);
     }
 }
 private void CompareNavigationProperty(NavigationProperty expectedNavigationProperty, NavigationProperty actualNavigationProperty)
 {
     this.CompareAssociationType(expectedNavigationProperty.Association, actualNavigationProperty.Association);
     this.CompareAssociationEnd(expectedNavigationProperty.FromAssociationEnd, actualNavigationProperty.FromAssociationEnd);
     this.CompareAssociationEnd(expectedNavigationProperty.ToAssociationEnd, actualNavigationProperty.ToAssociationEnd);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Generates the navigation property.
        /// </summary>
        /// <param name="xmlNamespace">The XML namespace.</param>
        /// <param name="prop">The Navigation property.</param>
        /// <returns>IEnumerable of XElement</returns>
        protected override XElement GenerateNavigationProperty(XNamespace xmlNamespace, NavigationProperty prop)
        {
            var content = base.GenerateNavigationProperty(xmlNamespace, prop);
            PropertyAccessModifierAnnotation accessModifierAnnotation = prop.Annotations.OfType<PropertyAccessModifierAnnotation>().SingleOrDefault();
            if (accessModifierAnnotation != null)
            {
                content.Add(GeneratePropertyAccessModifier(accessModifierAnnotation));
            }

            return content;
        }
 /// <summary>
 /// Adds initialization for a property if any is needed
 /// </summary>
 /// <param name="navigationProperty">The property to initialize</param>
 /// <param name="parentClassConstructor">The constructor to add to</param>
 protected virtual void DeclareOptionalPropertyInitializer(NavigationProperty navigationProperty, CodeConstructor parentClassConstructor)
 {
     // right now, we only need to initialize collection navigations
     if (navigationProperty.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
     {
         var type = this.GetPropertyType(navigationProperty, CodeGenerationTypeUsage.Instantiation);
         parentClassConstructor.Statements.Add(Code.This().Property(navigationProperty.Name).Assign(Code.New(type)));
     }
 }
 /// <summary>
 /// Adds a navigation property to the given type declaration based on the given metadata
 /// </summary>
 /// <param name="navigationProperty">The property's metadata</param>
 /// <param name="parentClass">The type declaration</param>
 protected override void DeclareNavigationProperty(NavigationProperty navigationProperty, CodeTypeDeclaration parentClass)
 {
     parentClass.AddAutoImplementedProperty(this.GetPropertyType(navigationProperty, CodeGenerationTypeUsage.Declaration), navigationProperty.Name);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Adds given navigation property to <see cref="NavigationProperties"/> collection.
 /// </summary>
 /// <param name="prop">Navigation property to add.</param>
 public void Add(NavigationProperty prop)
 {
     this.NavigationProperties.Add(prop);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the NavigationSegment class
 /// </summary>
 /// <param name="property">The navigation property</param>
 internal NavigationSegment(NavigationProperty property)
     : base()
 {
     this.NavigationProperty = property;
 }
Exemplo n.º 9
0
        private void CompareNavigationProperty(NavigationProperty expectedNavigationProperty, NavigationProperty actualNavigationProperty)
        {
            this.SatisfiesEquals(expectedNavigationProperty.Name, actualNavigationProperty.Name, "Navigation property name does not match.");

            this.SatisfiesEquals(
                expectedNavigationProperty.Association.FullName,
                actualNavigationProperty.Association.FullName,
                "Association does not match for navigation property '{0}'.",
                expectedNavigationProperty.Name);

            this.SatisfiesEquals(
                expectedNavigationProperty.FromAssociationEnd.RoleName,
                actualNavigationProperty.FromAssociationEnd.RoleName,
                "FromAssociationEnd does not match for navigation property '{0}'.",
                expectedNavigationProperty.Name);

            this.SatisfiesEquals(
                expectedNavigationProperty.ToAssociationEnd.RoleName,
                actualNavigationProperty.ToAssociationEnd.RoleName,
                "ToAssociationEnd does not match for navigation property '{0}'.",
                expectedNavigationProperty.Name);
        }
Exemplo n.º 10
0
        private NavigationProperty ParseNavigationProperty(XElement navigationPropertyElement)
        {
            var name = navigationPropertyElement.GetRequiredAttributeValue("Name");
            string relationshipNamespace = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[0];
            string relationshipName = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[1];

            string fromRole = navigationPropertyElement.GetRequiredAttributeValue("FromRole");
            string toRole = navigationPropertyElement.GetRequiredAttributeValue("ToRole");

            var navProp = new NavigationProperty(name, new AssociationTypeReference(relationshipNamespace, relationshipName), fromRole, toRole);
            this.ParseAnnotations(navProp, navigationPropertyElement);

            string getteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "GetterAccess", null);
            string setteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "SetterAccess", null);
            if (getteraccess != null || setteraccess != null)
            {
                AccessModifier setter;
                AccessModifier getter;
                this.GetGetterAndSetterModifiers(getteraccess, setteraccess, out setter, out getter);
                navProp.Annotations.Add(new PropertyAccessModifierAnnotation(setter, getter));
            }

            return navProp;
        }
        /// <summary>
        /// Returns the type to use when declaring or instantiating the property
        /// </summary>
        /// <param name="property">The property being declared/instantiated</param>
        /// <param name="usage">The usage for the type (either for instantiation or declaration)</param>
        /// <returns>The type of the property</returns>
        protected CodeTypeReference GetPropertyType(NavigationProperty property, CodeGenerationTypeUsage usage)
        {
            var type = DataTypes.EntityType.WithDefinition(property.ToAssociationEnd.EntityType);
            if (property.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
            {
                return this.GetCollectionType(usage, property.Annotations, type);
            }

            return this.BackingTypeResolver.ResolveClrTypeReference(type);
        }
 /// <summary>
 /// Adds a navigation property to the given type declaration based on the given metadata
 /// </summary>
 /// <param name="navigationProperty">The property's metadata</param>
 /// <param name="parentClass">The type declaration</param>
 protected abstract void DeclareNavigationProperty(NavigationProperty navigationProperty, CodeTypeDeclaration parentClass);
Exemplo n.º 13
0
 /// <summary>
 /// Adds given navigation property to <see cref="NavigationProperties"/> collection.
 /// </summary>
 /// <param name="prop">Navigation property to add.</param>
 public void Add(NavigationProperty prop)
 {
     this.NavigationProperties.Add(prop);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Visits navigation property
 /// </summary>
 /// <param name="navigationProperty">navigation property to visit</param>
 protected virtual void VisitNavigationProperty(NavigationProperty navigationProperty)
 {
     this.VisitAnnotatedItem(navigationProperty);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Generates the navigation property.
 /// </summary>
 /// <param name="xmlNamespace">The XML namespace.</param>
 /// <param name="prop">The Navigation property.</param>
 /// <returns>IEnumerable of XElement</returns>
 protected virtual XElement GenerateNavigationProperty(XNamespace xmlNamespace, NavigationProperty prop)
 {
     return new XElement(
         xmlNamespace + "NavigationProperty",
         new XAttribute("Name", prop.Name),
         new XAttribute("Relationship", this.GetFullyQualifiedName(prop.Association)),
         new XAttribute("FromRole", prop.FromAssociationEnd.RoleName),
         new XAttribute("ToRole", prop.ToAssociationEnd.RoleName),
         this.GenerateDocumentation(xmlNamespace, prop),
         this.GenerateAnnotations(xmlNamespace, prop));
 }