예제 #1
0
        public void FindWithCompositeKeys()
        {
            var keyInfos = PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(typeof(CustomerWithThreeCompositePrimaryKey));

            Assert.Equal(3, keyInfos.Length);
            Assert.Equal(nameof(CustomerWithThreeCompositePrimaryKey.Id1), keyInfos[0].Name);
            Assert.Equal(nameof(CustomerWithThreeCompositePrimaryKey.Id2), keyInfos[1].Name);
            Assert.Equal(nameof(CustomerWithThreeCompositePrimaryKey.Id3), keyInfos[2].Name);
        }
        /// <summary>
        /// Gets the default conventions.
        /// </summary>
        public static IRepositoryConventions Default()
        {
            var conventions = new RepositoryConventions
            {
                PrimaryKeysCallback = pi => PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(pi)
            };

            return(conventions);
        }
        /// <summary>
        /// Gets the default conventions.
        /// </summary>
        /// <typeparam name="TOwner">The type that owns this conventions.</typeparam>
        public static IRepositoryConventions Default <TOwner>() where TOwner : IRepositoryContext
        {
            var conventions = new RepositoryConventions(typeof(TOwner));

            conventions.PrimaryKeysCallback      = pi => PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(conventions, pi);
            conventions.ForeignKeysCallback      = (sourceType, foreignType) => ForeignKeyConventionHelper.GetForeignKeyPropertyInfos(conventions, sourceType, foreignType);
            conventions.TableNameCallback        = type => ModelConventionHelper.GetTableName(type);
            conventions.ColumnNameCallback       = pi => ModelConventionHelper.GetColumnName(pi);
            conventions.ColumnOrderCallback      = pi => ModelConventionHelper.GetColumnOrder(conventions, pi);
            conventions.IsColumnIdentityCallback = pi => ModelConventionHelper.IsColumnIdentity(conventions, pi);
            conventions.IsColumnMappedCallback   = pi => ModelConventionHelper.IsColumnMapped(pi);

            return(conventions);
        }
예제 #4
0
        public void CannotFindWhenEntityHasNoKeys()
        {
            var keyInfos = PrimaryKeyConventionHelper.GetPrimaryKeyPropertyInfos(typeof(CustomerWithNoId));

            Assert.Empty(keyInfos);
        }