当前位置: 首页>>代码示例>>C#>>正文


C# EntityType.AddIndex方法代码示例

本文整理汇总了C#中EntityType.AddIndex方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.AddIndex方法的具体用法?C# EntityType.AddIndex怎么用?C# EntityType.AddIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EntityType的用法示例。


在下文中一共展示了EntityType.AddIndex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Indexes_are_ordered_by_property_count_then_property_names

        public void Indexes_are_ordered_by_property_count_then_property_names()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var idProperty = customerType.GetOrAddProperty(Customer.IdProperty);
            var nameProperty = customerType.GetOrAddProperty(Customer.NameProperty);
            var otherProperty = customerType.GetOrAddProperty("OtherProperty", typeof(string), shadowProperty: true);

            var i2 = customerType.AddIndex(nameProperty);
            var i4 = customerType.AddIndex(new[] { idProperty, otherProperty });
            var i3 = customerType.AddIndex(new[] { idProperty, nameProperty });
            var i1 = customerType.AddIndex(idProperty);

            Assert.True(new[] { i1, i2, i3, i4 }.SequenceEqual(customerType.Indexes));
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:14,代码来源:EntityTypeTest.cs

示例2: CreateModel

        private static IModel CreateModel()
        {
            var model = new Metadata.Model { StorageName = "MyDatabase" };

            var dependentEntityType = new EntityType("Dependent");
            dependentEntityType.SetSchema("dbo");
            dependentEntityType.SetTableName("MyTable0");

            var principalEntityType = new EntityType("Principal");
            principalEntityType.SetSchema("dbo");
            principalEntityType.SetTableName("MyTable1");

            var dependentProperty = dependentEntityType.AddProperty("Id", typeof(int));
            var principalProperty = principalEntityType.AddProperty("Id", typeof(int));
            principalProperty.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;

            model.AddEntityType(principalEntityType);
            model.AddEntityType(dependentEntityType);

            principalProperty.Annotations.Add(new Annotation(
                MetadataExtensions.Annotations.StorageTypeName, "int"));
            dependentProperty.Annotations.Add(new Annotation(
                MetadataExtensions.Annotations.StorageTypeName, "int"));

            dependentEntityType.SetKey(dependentProperty);
            principalEntityType.SetKey(principalProperty);
            dependentEntityType.GetKey().SetKeyName("MyPK0");
            principalEntityType.GetKey().SetKeyName("MyPK1");

            var foreignKey = dependentEntityType.AddForeignKey(principalEntityType.GetKey(), dependentProperty);
            foreignKey.SetKeyName("MyFK");
            foreignKey.Annotations.Add(new Annotation(
                MetadataExtensions.Annotations.CascadeDelete, "True"));

            var index = dependentEntityType.AddIndex(dependentProperty);
            index.SetIndexName("MyIndex");
            index.IsUnique = true;

            return model;
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:40,代码来源:DatabaseBuilderTest.cs

示例3: AddIndex_throws_if_duplicate

        public void AddIndex_throws_if_duplicate()
        {
            var entityType = new EntityType(typeof(Customer), new Model());
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);
            entityType.AddIndex(new[] { property1, property2 });

            Assert.Equal(Strings.DuplicateIndex("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Customer).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => entityType.AddIndex(new[] { property1, property2 })).Message);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:11,代码来源:EntityTypeTest.cs

示例4: GetIndex_throws_if_index_not_found

        public void GetIndex_throws_if_index_not_found()
        {
            var entityType = new EntityType(typeof(Customer), new Model());
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);

            Assert.Equal(Strings.IndexNotFound("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Customer).FullName),
                Assert.Throws<ModelItemNotFoundException>(
                    () => entityType.GetIndex(new[] { property1, property2 })).Message);

            entityType.AddIndex(property1);

            Assert.Equal(Strings.IndexNotFound("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Customer).FullName),
                Assert.Throws<ModelItemNotFoundException>(
                    () => entityType.GetIndex(new[] { property1, property2 })).Message);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:16,代码来源:EntityTypeTest.cs

示例5: AddIndex_throws_if_not_from_same_entity

        public void AddIndex_throws_if_not_from_same_entity()
        {
            var entityType1 = new EntityType(typeof(Customer), new Model());
            var entityType2 = new EntityType(typeof(Order), new Model());
            var property1 = entityType1.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType1.GetOrAddProperty(Customer.NameProperty);

            Assert.Equal(Strings.IndexPropertiesWrongEntity("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Order).FullName),
                Assert.Throws<ArgumentException>(
                    () => entityType2.AddIndex(new[] { property1, property2 })).Message);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:11,代码来源:EntityTypeTest.cs

示例6: Can_add_retrieve_and_remove_indexes

        public void Can_add_retrieve_and_remove_indexes()
        {
            var entityType = new EntityType(typeof(Order), new Model());
            var property1 = entityType.GetOrAddProperty(Order.IdProperty);
            var property2 = entityType.GetOrAddProperty(Order.CustomerIdProperty);

            Assert.Equal(0, entityType.Indexes.Count);
            Assert.Null(entityType.RemoveIndex(new Index(new[] { property1 })));

            var index1 = entityType.GetOrAddIndex(property1);

            Assert.Equal(1, index1.Properties.Count);
            Assert.Same(index1, entityType.GetIndex(property1));
            Assert.Same(index1, entityType.FindIndex(property1));
            Assert.Same(property1, index1.Properties[0]);

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

            Assert.Equal(2, index2.Properties.Count);
            Assert.Same(index2, entityType.GetOrAddIndex(new[] { property1, property2 }));
            Assert.Same(index2, entityType.FindIndex(new[] { property1, property2 }));
            Assert.Same(property1, index2.Properties[0]);
            Assert.Same(property2, index2.Properties[1]);

            Assert.Equal(2, entityType.Indexes.Count);
            Assert.Same(index1, entityType.Indexes[0]);
            Assert.Same(index2, entityType.Indexes[1]);

            Assert.Same(index1, entityType.RemoveIndex(index1));
            Assert.Null(entityType.RemoveIndex(index1));

            Assert.Equal(1, entityType.Indexes.Count);
            Assert.Same(index2, entityType.Indexes[0]);

            Assert.Same(index2, entityType.RemoveIndex(new Index(new[] { property1, property2 })));

            Assert.Equal(0, entityType.Indexes.Count);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:38,代码来源:EntityTypeTest.cs

示例7: AddIndex_validates_properties_from_same_entity

        public void AddIndex_validates_properties_from_same_entity()
        {
            var entityType1 = new EntityType("E1");
            var entityType2 = new EntityType("E2");

            var property1 = entityType1.AddProperty(Customer.IdProperty);
            var property2 = entityType1.AddProperty(Customer.NameProperty);

            Assert.Equal(Strings.FormatIndexPropertiesWrongEntity(entityType2.Name),
                Assert.Throws<ArgumentException>(
                    () => entityType2.AddIndex(property1, property2)).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:12,代码来源:EntityTypeTest.cs

示例8: AddIndex_check_arguments

        public void AddIndex_check_arguments()
        {
            var entityType = new EntityType(typeof(Order));

            Assert.Equal(
                "properties",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => entityType.AddIndex(null)).ParamName);

            Assert.Equal(
                Strings.FormatCollectionArgumentIsEmpty("properties"),
                Assert.Throws<ArgumentException>(() => entityType.AddIndex(new Property[0])).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:EntityTypeTest.cs

示例9: Can_add_retrieve_and_remove_indexes

        public void Can_add_retrieve_and_remove_indexes()
        {
            var entityType = new EntityType(typeof(Order));
            var property1 = entityType.AddProperty(Order.IdProperty);
            var property2 = entityType.AddProperty(Order.CustomerIdProperty);

            Assert.Equal(0, entityType.Indexes.Count);

            var index1 = entityType.AddIndex(property1);

            Assert.Equal(1, index1.Properties.Count);
            Assert.Same(property1, index1.Properties[0]);

            var index2 = entityType.AddIndex(property1, property2);

            Assert.Equal(2, index2.Properties.Count);
            Assert.Same(property1, index2.Properties[0]);
            Assert.Same(property2, index2.Properties[1]);

            Assert.Equal(2, entityType.Indexes.Count);
            Assert.Same(index1, entityType.Indexes[0]);
            Assert.Same(index2, entityType.Indexes[1]);

            entityType.RemoveIndex(index1);

            Assert.Equal(1, entityType.Indexes.Count);
            Assert.Same(index2, entityType.Indexes[0]);

            entityType.RemoveIndex(index2);

            Assert.Equal(0, entityType.Indexes.Count);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:32,代码来源:EntityTypeTest.cs


注:本文中的EntityType.AddIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。