Skip to content

How to implement "entity joins" with filtering in Hot Chocolate #4106

Answered by anilknarayan
KaTo-79 asked this question in Q&A
Discussion options

You must be logged in to vote

Something like this
`
using HotChocolate;
using HotChocolate.Data;

namespace YourNameSpace
{
public class Query
{
[UseDbContext(typeof(YourDbContext))]
[UseFiltering]
[UseProjection]
public IQueryable GetSites(
[ScopedService] YourDbContext context)
{
return context.Sites;
}
}

public partial class Company
{
    public Company()
    {
        Sites = new HashSet<Site>();
    }

    public string Name { get; set; }

[UseFiltering]
    public virtual ICollection<Site> Sites { get; set; }

}

public partial class Site
{
      public Site() {}
    
      public string Name { get; set; }
  [UseFiltering]
  public Company Company { get; set; }
}

}
`
Note the use of UseFiltering attribute in the …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@KaTo-79
Comment options

Answer selected by KaTo-79
Comment options

You must be logged in to vote
1 reply
@Sonic198
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants