Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:46:49+00:00 2026-06-18T02:46:49+00:00

My question is this: How can you implement a default server-side filter for a

  • 0

My question is this: How can you implement a default server-side “filter” for a navigation property?

In our application we seldom actually delete anything from the database. Instead, we implement “soft deletes” where each table has a Deleted bit column. If this column is true the record has been “deleted”. If it is false, it has not.

This allows us to easily “undelete” records accidentally deleted by the client.

Our current ASP.NET Web API returns only “undeleted” records by default, unless a deleted argument is sent as true from the client. The idea is that the consumer of the service doesn’t have to worry about specifying that they only want undeleted items.

Implementing this same functionality in Breeze is quite simple, at least for base entities. For example, here would be the implementation of the classic Todo’s example, adding a “Deleted” bit field:

    // Note: Will show only undeleted items by default unless you explicitly pass deleted = true.
    [HttpGet]
    public IQueryable<BreezeSampleTodoItem> Todos(bool deleted = false) {
        return _contextProvider.Context.Todos.Where(td => td.Deleted == deleted);
    }

On the client, all we need to do is…

var query = breeze.EntityQuery.from("Todos");

…to get all undeleted Todos, or…

var query = breeze.EntityQuery.from("Todos").withParameters({deleted: true})

…to get all deleted Todos.

But let’s say that a BreezeSampleTodoItem has a child collection for the tools that are needed to complete that Todo. We’ll call this “Tools”. Tools also implements soft deletes. When we perform a query that uses expand to get a Todo with its Tools, it will return all Tools – “deleted” or not.

But how can I filter out these records by default when Todo.Tools is expanded?

It has occurred to me to have separate Web API methods for each item that may need expanded, for example:

[HttpGet]
public IQueryable<Todo> TodoAndTools(bool deletedTodos = false, bool deletedTools = false)
{
    return // ...Code to get filtered Todos with filtered Tools
}

I found some example code of how to do this in another SO post, but it requires hand-coding each property of Todo. The code from the above-mentioned post also returns a List, not an IQueryable. Furthermore this requires methods to be added for every possible expansion which isn’t cool.

Essentially what I’m looking for is some way to define a piece of code that gets called whenever Todos is queried, and another for whenever Tools is queried – preferably being able to pass an argument that defines if it should return Deleted items. This could be anywhere on the server-side stack – be it in the Web API method, itself, or maybe part of Entity Framework (note that filtering Include extensions is not supported in EF.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:46:50+00:00Added an answer on June 18, 2026 at 2:46 am

    Breeze cannot do exactly what you are asking for right now, although we have discussed the idea of allowing the filtering of “expands”, but we really need more feedback as to whether the community would find this useful. Please add this to the breeze User Voice and vote for it. We take these suggestions very seriously.

    Moreover, as you point out, EF does not support this.

    But… what you can do is use a projection instead of an expand to do something very similar:

    public IQueryable<Object> TodoAndTools(bool deleted = false
                                          ,bool deletedTools = false) {
        var baseQuery = _contextProvider.Context.Todos.Where(td => td.Deleted == deleted);
        return baseQuery.Select(t => new {
          Todo: t,
          Tools: t.Tools.Where( tool => tool.Deleted = deletedTools);
        });
     }
    

    Several things to note here:

    1) We are returning an IQueryable of Object instead of IQueryable of ToDo

    2) Breeze will inspect the returned payload and automatically create breeze entities for any ‘entityTypes’ returned (even within a projection). So the result of this query will be an array of javascript objects each with two properties; ‘ToDo’ and ‘Tools’ where Tools is an array of ‘Tool’ entities. The nice thing is that both ToDo and Tool entities returned within the projection will be ‘full’ breeze entities.

    3) You can still pass client side filters based on the projected property names. i.e.

    var query = EntityQuery.from("TodoAndTools")
            .where("Todo.Description", "startsWith", "A")
            .using(em);
    

    4) EF does support this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a further question based on this answer: How can I implement a
I am using the SQL Server PHP Driver, I think this question can be
I know this question can be answered by searching in google. But I have
I am using the jQuery-File-Upload widget (although I believe this question can generalize to
I have not been able to find any definitive answers to this question: Can
I asked a question about different testing frameworks yesterday. This question can be found
<hyperbole> Whoever answers this question can claim credit for solving the world's most challenging
I know this can seem a weird question but for me it would be
You can read this question where I ask about the best architecture for a
This can be a good question for finding bugs. No? Okay for beginners at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.