gpt4 book ai didi

c# - 基于子集合的父级热巧克力自定义过滤器

转载 作者:行者123 更新时间:2023-12-04 11:45:22 24 4
gpt4 key购买 nike

我正在尝试实现类似于 described here过滤模型 hotchocolate代码优先的方法。如果至少有一位 Actor 符合某些标准,我需要过滤电影。模型看起来像这样:

public class Movie
{
public IList<Actor> Actors { get; set; }
}

public class Actor { }

public class MovieTypeDef : ObjectType<Movie>
{
protected override void Configure(IObjectTypeDescriptor<Movie> descriptor)
{
descriptor.Field(x => x.Actors)
.Type<NonNullType<ListType<NonNullType<ActorTypeDef>>>>();
}
}

public class ActorTypeDef : ObjectType<Actor> { }

public class Query
{
public IList<Movie> Movies()
{
return new List<Movie>();
}
}

public class QueryTypeDef : ObjectType<Query>
{
protected override void Configure(IObjectTypeDescriptor<Query> descriptor)
{
descriptor.Field(x => x.Movies())
.Type<NonNullType<ListType<MovieTypeDef>>>()
.UseFiltering<MoviesFileringTypeDef>();
}
}

public class MoviesFileringTypeDef : FilterInputType<Movie>
{
protected override void Configure(IFilterInputTypeDescriptor<Movie> descriptor)
{
descriptor.Filter(x => x.Actors) // compilation error
}
}

似乎无法向 MoviesFileringTypeDef 添加自定义过滤器因为它只允许使用 Movie 的属性类,那里不接受收藏。
是否可以用热巧克力实现这样的过滤器?

最佳答案

I also faced a similar kind of issue while I was trying to apply a filter on the parent entity based on the child entity field. I believe in your case you need to apply a filter in your MovieTypeDef also with QueryType as below:-

public class MovieTypeDef : ObjectType<Movie>
{
protected override void Configure(IObjectTypeDescriptor<Movie> descriptor)
{
descriptor.Field(x => x.Actors)
.Type<NonNullType<ListType<NonNullType<ActorTypeDef>>>>()
.UseFiltering<YourModel>();;
}
}

After this change, you can apply a filter on a nested level also as you can apply with the parent level.

关于c# - 基于子集合的父级热巧克力自定义过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60898798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com