public void Apply_is_noop_when_unknown_dependent()
        {
            var model           = new EdmModel(DataSpace.CSpace);
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var navigationProperty = new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            };
            var foreignKeyAnnotation = new ForeignKeyAttribute("AId");

            navigationProperty.GetMetadataProperties().SetClrAttributes(new[] { foreignKeyAnnotation });

            (new ForeignKeyNavigationPropertyAttributeConvention())
            .Apply(navigationProperty, new DbModel(model, null));

            Assert.Null(associationType.Constraint);
        }
Exemplo n.º 2
0
        public void Map(
            PropertyInfo propertyInfo,
            EntityType entityType,
            Func <EntityTypeConfiguration> entityTypeConfiguration)
        {
            Type elementType = propertyInfo.PropertyType;
            RelationshipMultiplicity relationshipMultiplicity = RelationshipMultiplicity.ZeroOrOne;

            if (elementType.IsCollection(out elementType))
            {
                relationshipMultiplicity = RelationshipMultiplicity.Many;
            }
            EntityType targetEntityType = this._typeMapper.MapEntityType(elementType);

            if (targetEntityType == null)
            {
                return;
            }
            RelationshipMultiplicity sourceAssociationEndKind = relationshipMultiplicity.IsMany() ? RelationshipMultiplicity.ZeroOrOne : RelationshipMultiplicity.Many;
            AssociationType          associationType          = this._typeMapper.MappingContext.Model.AddAssociationType(entityType.Name + "_" + propertyInfo.Name, entityType, sourceAssociationEndKind, targetEntityType, relationshipMultiplicity, this._typeMapper.MappingContext.ModelConfiguration.ModelNamespace);

            associationType.SourceEnd.SetClrPropertyInfo(propertyInfo);
            this._typeMapper.MappingContext.Model.AddAssociationSet(associationType.Name, associationType);
            NavigationProperty property = entityType.AddNavigationProperty(propertyInfo.Name, associationType);

            property.SetClrPropertyInfo(propertyInfo);
            this._typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(propertyInfo, (Func <PropertyConfiguration>)(() => (PropertyConfiguration)entityTypeConfiguration().Navigation(propertyInfo)), this._typeMapper.MappingContext.ModelConfiguration);
            new AttributeMapper(this._typeMapper.MappingContext.AttributeProvider).Map(propertyInfo, (ICollection <MetadataProperty>)property.GetMetadataProperties());
        }
Exemplo n.º 3
0
        public static void SetConfiguration(this NavigationProperty navigationProperty, object configuration)
        {
            DebugCheck.NotNull(navigationProperty);

            navigationProperty.GetMetadataProperties().SetConfiguration(configuration);
        }
Exemplo n.º 4
0
 public static void SetConfiguration(
     this NavigationProperty navigationProperty,
     object configuration)
 {
     navigationProperty.GetMetadataProperties().SetConfiguration(configuration);
 }