public virtual bool Apply(InternalKeyBuilder keyBuilder, Key previousPrimaryKey)
        {
            var entityTypeBuilder = keyBuilder.ModelBuilder.Entity(
                keyBuilder.Metadata.DeclaringEntityType.Name, ConfigurationSource.Convention);

            if (previousPrimaryKey != null)
            {
                foreach (var property in previousPrimaryKey.Properties)
                {
                    if (entityTypeBuilder.Metadata.FindProperty(property.Name) != null)
                    {
                        entityTypeBuilder.Property(property.Name, ConfigurationSource.Convention)
                            ?.ValueGenerated(null, ConfigurationSource.Convention);
                    }
                }
            }

            var valueGeneratedOnAddProperty = FindValueGeneratedOnAddProperty(keyBuilder.Metadata.Properties);
            if (valueGeneratedOnAddProperty != null
                && !valueGeneratedOnAddProperty.IsForeignKey(entityTypeBuilder.Metadata))
            {
                SetIdentity(entityTypeBuilder, valueGeneratedOnAddProperty);
            }

            return true;
        }
Exemple #2
0
        public void Can_create_key_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);

            var key = new Key(new[] { property1, property2 });

            Assert.True(new[] { property1, property2 }.SequenceEqual(key.Properties));
        }