Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasQueryFilter on Relationship #30339

Closed
MoishyS opened this issue Feb 24, 2023 · 2 comments
Closed

HasQueryFilter on Relationship #30339

MoishyS opened this issue Feb 24, 2023 · 2 comments

Comments

@MoishyS
Copy link

MoishyS commented Feb 24, 2023

I would like to be able to have properties with filtered relationships. for example.

public class Blog
{
    public int BlogId { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }

    public List<Post> Posts { get; set; }

    public List<Post> DeletedPosts { get; set; }
    public List<Post> PopularPosts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public int Votes { get; set; }
    public bool IsDeleted { get; set; }

    public Blog Blog { get; set; }
}

and OnModelCreating

modelBuilder.Entity<Blog>()
        .HasMany(b => b.DeletedPosts)
        .WithOne(p => p.Blog)
        .HasQueryFilter(p => p.IsDeleted);

modelBuilder.Entity<Blog>()
        .HasMany(b => b.PopularPosts)
        .WithOne(p => p.Blog)
        .HasQueryFilter(p => p.Votes > 100);
@ajcvickers
Copy link
Member

Duplicate of #20339. Please vote (👍) for that issue.

@roji
Copy link
Member

roji commented Feb 25, 2023

Duplicate of #20339

@roji roji marked this as a duplicate of #20339 Feb 25, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants