示例#1
0
        private void ApplyConfigurationToField <TEntity, TType>(
            IObjectFieldDescriptor field,
            bool withPaging)
            where TEntity : class
            where TType : SortInputType <TEntity>
        {
            field.Use(
                next => async context =>
            {
                await next(context);

                if (context.Result is IQueryable <TEntity> queryable)
                {
                    try
                    {
                        context.ContextData["sql"] = queryable.ToQueryString();
                    }
                    catch (Exception)
                    {
                        context.ContextData["sql"] =
                            "EF Core 3.1 does not support ToQueryString";
                    }
                }
            });

            if (withPaging)
            {
                field.UsePaging <ObjectType <TEntity> >();
            }

            field.UseSorting <TType>();
        }
 public override void OnConfigure(IObjectFieldDescriptor descriptor)
 {
     if (SortType is null)
     {
         descriptor.UseSorting();
     }
     else
     {
         _generic.MakeGenericMethod(SortType).Invoke(null, new[] { descriptor });
     }
 }
 public override void OnConfigure(
     IDescriptorContext context,
     IObjectFieldDescriptor descriptor,
     MemberInfo member)
 {
     if (Type is null)
     {
         descriptor.UseSorting(Scope);
     }
     else
     {
         _generic.MakeGenericMethod(Type).Invoke(
             null,
             new object?[] { descriptor, Scope });
     }
 }