/// <summary>
        ///     Configures a query used to provide data for an entity type.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
        /// <param name="query"> The query that will provide the underlying data for the entity type. </param>
        /// <returns> The same builder instance so that multiple calls can be chained. </returns>
        public static EntityTypeBuilder <TEntity> ToQuery <TEntity>(
            [NotNull] this EntityTypeBuilder <TEntity> entityTypeBuilder,
            [NotNull] Expression <Func <IQueryable <TEntity> > > query)
            where TEntity : class
        {
            Check.NotNull(query, nameof(query));

            InMemoryEntityTypeExtensions.SetDefiningQuery(entityTypeBuilder.Metadata, query);

            return(entityTypeBuilder);
        }
        /// <summary>
        ///     Configures a query used to provide data for an entity type.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
        /// <param name="query"> The query that will provide the underlying data for the entity type. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the query was set, <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionEntityTypeBuilder HasDefiningQuery(
            [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
            [CanBeNull] LambdaExpression query,
            bool fromDataAnnotation = false)
        {
            if (CanSetDefiningQuery(entityTypeBuilder, query, fromDataAnnotation))
            {
                InMemoryEntityTypeExtensions.SetDefiningQuery(entityTypeBuilder.Metadata, query, fromDataAnnotation);

                return(entityTypeBuilder);
            }

            return(null);
        }