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


C# EntityType.FindPrimaryKey方法代码示例

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


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

示例1: GetCompatiblePrimaryKeyProperties

        private static IReadOnlyList<Property> GetCompatiblePrimaryKeyProperties(EntityType dependentEntityType, EntityType principalEntityType, IReadOnlyList<Property> propertiesToReference)
        {
            var dependentPkProperties = dependentEntityType.FindPrimaryKey()?.Properties;
            if ((dependentPkProperties != null)
                && ForeignKey.AreCompatible(
                    propertiesToReference,
                    dependentPkProperties,
                    principalEntityType,
                    dependentEntityType,
                    shouldThrow: false))
            {
                return dependentPkProperties;
            }

            return null;
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:16,代码来源:ForeignKeyPropertyDiscoveryConvention.cs

示例2: GetCompatiblePrimaryKeyProperties

        private IReadOnlyList<Property> GetCompatiblePrimaryKeyProperties(EntityType entityType, IReadOnlyList<Property> propertiesToReference)
        {
            var dependentPkProperties = entityType.FindPrimaryKey()?.Properties;
            if (dependentPkProperties != null
                && Property.AreCompatible(propertiesToReference, dependentPkProperties))
            {
                return dependentPkProperties;
            }

            return null;
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:11,代码来源:ForeignKeyPropertyDiscoveryConvention.cs

示例3: 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.Keys.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.Keys.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.Keys.Count);

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

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


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