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


C# EntityType.GetKeys方法代码示例

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


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

示例1: Keys_are_ordered_by_property_count_then_property_names

        public void Keys_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 otherNameProperty = customerType.GetOrAddProperty("OtherNameProperty", typeof(string), shadowProperty: true);

            var k2 = customerType.GetOrAddKey(nameProperty);
            var k4 = customerType.GetOrAddKey(new[] { idProperty, otherNameProperty });
            var k3 = customerType.GetOrAddKey(new[] { idProperty, nameProperty });
            var k1 = customerType.GetOrAddKey(idProperty);

            Assert.True(new[] { k1, k2, k3, k4 }.SequenceEqual(customerType.GetKeys()));
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:14,代码来源:EntityTypeTest.cs

示例2: Can_add_and_get_a_key

        public void Can_add_and_get_a_key()
        {
            var entityType = new EntityType(typeof(Customer), new Model());
            var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
            var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);

            var key1 = entityType.AddKey(new[] { idProperty, nameProperty });

            Assert.NotNull(key1);
            Assert.Same(key1, entityType.GetOrAddKey(new[] { idProperty, nameProperty }));
            Assert.Same(key1, entityType.GetKeys().Single());

            var key2 = entityType.GetOrAddKey(idProperty);

            Assert.NotNull(key2);
            Assert.Same(key2, entityType.GetKey(idProperty));
            Assert.Equal(2, entityType.GetKeys().Count());
            Assert.Contains(key1, entityType.GetKeys());
            Assert.Contains(key2, entityType.GetKeys());
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:20,代码来源:EntityTypeTest.cs

示例3: Can_remove_keys

        public void Can_remove_keys()
        {
            var entityType = new EntityType(typeof(Customer), new Model());
            var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
            var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);

            Assert.Equal(
                Strings.KeyNotFound("{'" + idProperty.Name + "', '" + nameProperty.Name + "'}", typeof(Customer).FullName),
                Assert.Throws<ModelItemNotFoundException>(() => entityType.GetKey(new[] { idProperty, nameProperty })).Message);
            Assert.Null(entityType.RemoveKey(new Key(new[] { idProperty })));

            var key1 = entityType.GetOrSetPrimaryKey(new[] { idProperty, nameProperty });
            var key2 = entityType.GetOrAddKey(idProperty);

            Assert.Equal(new[] { key2, key1 }, entityType.GetKeys().ToArray());

            Assert.Same(key1, entityType.RemoveKey(key1));
            Assert.Null(entityType.RemoveKey(key1));

            Assert.Equal(
                Strings.KeyNotFound("{'" + idProperty.Name + "', '" + nameProperty.Name + "'}", typeof(Customer).FullName),
                Assert.Throws<ModelItemNotFoundException>(() => entityType.GetKey(new[] { idProperty, nameProperty })).Message);

            Assert.Equal(new[] { key2 }, entityType.GetKeys().ToArray());

            Assert.Same(key2, entityType.RemoveKey(new Key(new[] { idProperty })));

            Assert.Empty(entityType.GetKeys());
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:29,代码来源:EntityTypeTest.cs

示例4: Can_get_set_reset_and_clear_primary_key

        public void Can_get_set_reset_and_clear_primary_key()
        {
            var entityType = new EntityType(typeof(Customer), new Model());
            var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
            var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);

            var key1 = entityType.GetOrSetPrimaryKey(new[] { idProperty, nameProperty });

            Assert.NotNull(key1);
            Assert.Same(key1, entityType.GetOrSetPrimaryKey(new[] { idProperty, nameProperty }));
            Assert.Same(key1, entityType.GetPrimaryKey());

            Assert.Same(key1, entityType.FindPrimaryKey());
            Assert.Same(key1, entityType.GetKeys().Single());

            var key2 = entityType.GetOrSetPrimaryKey(idProperty);

            Assert.NotNull(key2);
            Assert.NotEqual(key1, key2);
            Assert.Same(key2, entityType.GetOrSetPrimaryKey(idProperty));
            Assert.Same(key2, entityType.GetPrimaryKey());
            Assert.Same(key2, entityType.FindPrimaryKey());
            Assert.Equal(2, entityType.GetKeys().Count());
            Assert.Same(key1, entityType.GetKey(key1.Properties));
            Assert.Same(key2, entityType.GetKey(key2.Properties));

            Assert.Null(entityType.GetOrSetPrimaryKey((Property)null));

            Assert.Null(entityType.FindPrimaryKey());
            Assert.Equal(2, entityType.GetKeys().Count());

            Assert.Null(entityType.GetOrSetPrimaryKey(new Property[0]));

            Assert.Null(entityType.FindPrimaryKey());
            Assert.Equal(2, entityType.GetKeys().Count());
            Assert.Equal(
                Strings.EntityRequiresKey(typeof(Customer).FullName),
                Assert.Throws<ModelItemNotFoundException>(() => entityType.GetPrimaryKey()).Message);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:39,代码来源:EntityTypeTest.cs


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