예제 #1
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));
        }
예제 #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));
        }
예제 #3
0
        public void Can_create_unique_index_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);

            var index = new Index(new[] { property1, property2 }) { IsUnique = true };

            Assert.True(new[] { property1, property2 }.SequenceEqual(index.Properties));
            Assert.True(index.IsUnique.Value);
        }
예제 #4
0
        public void Can_create_index_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1  = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2  = entityType.GetOrAddProperty(Customer.NameProperty);

            var index = entityType.AddIndex(new[] { property1, property2 }, ConfigurationSource.Convention);

            Assert.True(new[] { property1, property2 }.SequenceEqual(index.Properties));
            Assert.False(index.IsUnique);
            Assert.Equal(ConfigurationSource.Convention, index.GetConfigurationSource());
        }
예제 #5
0
        public void Can_create_index_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1  = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2  = entityType.GetOrAddProperty(Customer.NameProperty);

            var index = new Index(new[] { property1, property2 });

            Assert.True(new[] { property1, property2 }.SequenceEqual(index.Properties));
            Assert.Null(index.IsUnique);
            Assert.False(((IIndex)index).IsUnique);
        }
예제 #6
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);

            property2.IsNullable = false;

            var key = entityType.AddKey(new[] { property1, property2 }, ConfigurationSource.Convention);

            Assert.True(new[] { property1, property2 }.SequenceEqual(key.Properties));
            Assert.Equal(ConfigurationSource.Convention, key.GetConfigurationSource());
        }
예제 #7
0
        public void Index_returns_same_instance_for_property_names()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            entityType.GetOrAddProperty(Order.IdProperty);
            entityType.GetOrAddProperty(Order.CustomerIdProperty);

            var indexBuilder = entityBuilder.Index(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, ConfigurationSource.Convention);

            Assert.NotNull(indexBuilder);
            Assert.Same(indexBuilder, entityBuilder.Index(new[] { Order.IdProperty, Order.CustomerIdProperty }, ConfigurationSource.Explicit));
        }
예제 #8
0
        public void Validates_properties_from_same_entity()
        {
            var entityType1 = new Model().AddEntityType(typeof(Customer));
            var entityType2 = new Model().AddEntityType(typeof(Order));
            var property1   = entityType1.GetOrAddProperty(Customer.IdProperty);
            var property2   = entityType2.GetOrAddProperty(Order.NameProperty);

            Assert.Equal(CoreStrings.KeyPropertiesWrongEntity($"{{'{property1.Name}', '{property2.Name}'}}", entityType1.DisplayName()),
                         Assert.Throws <ArgumentException>(
                             () => entityType1.AddKey(new[] { property1, property2 })).Message);
        }
예제 #9
0
        public void Validates_properties_from_same_entity()
        {
            var entityType1 = new Model().AddEntityType(typeof(Customer));
            var entityType2 = new Model().AddEntityType(typeof(Order));
            var property1   = entityType1.GetOrAddProperty(Customer.IdProperty);
            var property2   = entityType2.GetOrAddProperty(Order.NameProperty);

            Assert.Equal(CoreStrings.InconsistentEntityType("properties"),
                         Assert.Throws <ArgumentException>(
                             () => new Key(new[] { property1, property2 })).Message);
        }
예제 #10
0
        public void Validates_properties_from_same_entity()
        {
            var entityType1 = new Model().AddEntityType(typeof(Customer));
            var entityType2 = new Model().AddEntityType(typeof(Order));
            var property1 = entityType1.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType2.GetOrAddProperty(Order.NameProperty);

            Assert.Equal(CoreStrings.InconsistentEntityType("properties"),
                Assert.Throws<ArgumentException>(
                    () => new Key(new[] { property1, property2 })).Message);
        }
예제 #11
0
        public void Can_only_override_lower_source_key_using_property_names()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            entityType.GetOrAddProperty(Order.IdProperty);
            entityType.GetOrAddProperty(Order.CustomerIdProperty);

            var originalKeyBuilder = entityBuilder.Key(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, ConfigurationSource.Convention);
            var newKeyBuilder      = entityBuilder.Key(new[] { Order.IdProperty.Name }, ConfigurationSource.DataAnnotation);

            Assert.NotNull(newKeyBuilder);
            Assert.NotEqual(originalKeyBuilder, newKeyBuilder);
            Assert.Equal(Order.IdProperty.Name, entityType.GetPrimaryKey().Properties.Single().Name);

            var originalKeyBuilder2 = entityBuilder.Key(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, ConfigurationSource.Explicit);

            Assert.NotNull(originalKeyBuilder2);
            Assert.NotEqual(originalKeyBuilder, originalKeyBuilder2);

            Assert.Null(entityBuilder.Key(new[] { Order.IdProperty.Name }, ConfigurationSource.DataAnnotation));
            Assert.Equal(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, entityType.GetPrimaryKey().Properties.Select(p => p.Name).ToArray());
        }
        public void Can_only_override_existing_key_explicitly_using_clr_properties()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            entityType.SetPrimaryKey(new[] { entityType.GetOrAddProperty(Order.IdProperty), entityType.GetOrAddProperty(Order.CustomerIdProperty) });

            Assert.Null(entityBuilder.Key(new[] { Order.IdProperty }, ConfigurationSource.DataAnnotation));

            Assert.Equal(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, entityType.GetPrimaryKey().Properties.Select(p => p.Name).ToArray());

            Assert.NotNull(entityBuilder.Key(new[] { Order.IdProperty }, ConfigurationSource.Explicit));

            Assert.Equal(Order.IdProperty.Name, entityType.GetPrimaryKey().Properties.Single().Name);
        }