Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QUESTION: Is possible to include a filter inside a GetAllIncluding?

See original GitHub issue

Hi All,

This is not an issue. I am looking for an idea to solve my problem.

Let’s imaging the following case. I have two tables: Customer and ShipTo. The ShipTo table is a child of the Customer.

Customer fields: ID Name Type

ShipTo fields ID Name Address State (numeric) City (numeric) CustomerID

If I want to retrieve all my Customers including their ShipTos I would do something like this:

Repository.GetAllIncluding(x => x.ShipTo)

Considering Repository as the repository for Customer. All this is ok. This would retrieve all my customer including all their ShipTos.

Now, what happens if I would retrieve all my customers and only their ShipTos filter by state and city.

Considering the following records




ID NAME ADDRESS STATE CITY CUSTOMERID 1 A Prometeo 10 5 1 2 B Villa 11 6 1 3 C Dorada 10 5 2 4 D Florencia 10 4 2 5 E Valle 12 5 3

If I want the customers and only their ShipTos for State 10 and City 5, I would expect the following result:




ID NAME ADDRESS STATE CITY CUSTOMERID 1 A Prometeo 10 5 1 3 C Dorada 10 5 2

In my REST API for the Customer object, I am running the GetAll action. This triggers the CreateFilteredQuery method in my AppService, inside this method, I added something like this:

    protected override IQueryable<Customer> CreateFilteredQuery(PagedCustomerResultRequestDto input)
        List<int> shipTosListFiltered = new List<int>();

        if (!input.State.IsNullOrWhiteSpace() || !input.City.IsNullOrWhiteSpace())
            shipTosListFiltered = _shipToManager.GetShipTosInCityAndState(input.Town, input.State);

        return Repository.GetAllIncluding(x => x.ShipTo)                
            .WhereIf(shipTosListFiltered.Count > 0, pbs => pbs.ShipTo.Any(pb => shipTosListFiltered .Contains(pb.Id)));                

This retrieves the customer 1 and 2 correctly. But it returns me all their ShipTos and I would like them filtered.

Does someone know if there is a way to filter this as I am expecting?

I would really appreciate an idea for this.

Thanks in advance.

Regards, Arturo

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

ismcagdascommented, Apr 19, 2021

I was talking about a simpler query like below;

var query = from customer in Repository.GetAll()
                    join s in _shipToRepository.GetAll() on customer.Id equals s.CustomerId
                    into sg select new 
                        Customer = customer, 
                        ShipTo = sg 
stale[bot]commented, Jun 18, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GetAllIncluding With Optional Relationships ABP
I have an entity with some optional relationships and I'm doing a GetAllIncluding(someProperties) but the navigation properties keeps in null ...
Read more >
WhereIf not including Property #7184
Hi, I have the following part of code: var filteredDrivingLessons = _drivingLessonRepository.GetAllIncluding(e => e.
Read more >
ASP.NET MVC 5, EF 6 filter performance
I'm creating a filter with Linq in an ASP.NET MVC application. I was hoping I could get some tips on performance enhancements, aside...
Read more >
Ef Core filtering included query using uow and repository
I started creating a role-based security system in my WinForm application so I ... Ef Core filtering included query using uow and repository....
Read more >
Repositories | Documentation Center | ABP.IO
Database provider layer should be properly configured to be able to use the ... GetCountAsync method gets a filtered count of all people...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found