/// <summary> /// Adds a navigation property to the <paramref name="entityType"/>. This method creates an association type /// in order to add the navigation property. /// Returns the modified entity type for composability. /// </summary> /// <param name="entityType">The <see cref="EntityType"/> to add the navigation property to.</param> /// <param name="propertyName">The name of the property to add.</param> /// <param name="otherEndType">The type of the other end of the navigation property.</param> /// <param name="isSingletonRelationship">true if the navigation property is of singleton cardinality; false for a cardinality many. Default is false.</param> /// <returns>The <paramref name="entityType"/> instance after adding the navigation property to it.</returns> public static EntityType NavigationProperty(this EntityType entityType, string propertyName, EntityType otherEndType, bool isSingletonRelationship = false) { ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType"); ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName"); EntityModelSchema model = entityType.Model(); // create the association type between the two entity types AssociationType associationType = model.AssociationType(entityType, otherEndType, isSingletonRelationship); // add the navigation property to the generated entity type entityType.Add(new NavigationProperty(propertyName, associationType, associationType.Ends[0], associationType.Ends[1])); return(entityType); }