GithubHelp home page GithubHelp logo

How do you GetAll() ? about unitofwork HOT 27 CLOSED

arch avatar arch commented on September 14, 2024
How do you GetAll() ?

from unitofwork.

Comments (27)

Shawson avatar Shawson commented on September 14, 2024

Implemented in pull request #18

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

@Shawson Thanks.
The Query is deprecated because of SHOULD NOT expose the IQueryable<T> out of the Repository, that's to say we want all the database's roundtrip is Repository's internal logic.

We can use GetPagedList(pageIndex: 0, pageSize=maxvalue) to get the all records. Or maybe set the pageSize's default value to null to represent the all.

from unitofwork.

Shawson avatar Shawson commented on September 14, 2024

Thanks @xyting! How do you get hold of maxvalue to pass into pageSize?

I see where you're going with it now- guess this puts more of a priority on the custom repository support then?

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

If we change the pageSize to int? pageSize = 20 (default value not null for backward compatibility), pageSize: null represent get all. So we can set the Count value to PageSize and fetch the all from database.

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

If we not change the pageSize, we can use pageSize: int.MaxValue to get all, but, this is stupid.

from unitofwork.

Shawson avatar Shawson commented on September 14, 2024

yes- the null default is the better of those options I reckon!

from unitofwork.

Shawson avatar Shawson commented on September 14, 2024

Actually, thinking about it- why do you not want to expose IQueryable? I only ask because I will often grab a queryable from a repository then do a .Select to only grab the properties I'm interested in- this makes for a more efficient query to sql?

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

If expose IQueryable<TEntity> is acceptable, IQueryable<TEntity> Query(Expression<Func<TEntity, bool>> predicate = null, bool disableTracking = true); will be better, becuase it can be used for getting all or filter by the predicator. We only need to remove the Obsolete attribute and set the predicate optionable.

from unitofwork.

Shawson avatar Shawson commented on September 14, 2024

We could still keep the Paged methods, but get them to also return IQueryable- so it grabs a queryable, applies the Skip() & Take() then returns it back still as queryable, allowing for custom Select() to still be run against it.

from unitofwork.

Shawson avatar Shawson commented on September 14, 2024

justed commited #22 which changes paged lists to expose items as Queryable's and remove the Obsolete attribute from Query function

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

@Shawson Thanks for your good job!

from unitofwork.

farisyusry avatar farisyusry commented on September 14, 2024

i just add one more function in repository.cs

        public IQueryable<TEntity> GetAll()
        {
            return _dbSet.AsQueryable();
        }

so it will return iqueryable. and u can using LINQ/EF extension like where, order by, etc.

from unitofwork.

moattarwork avatar moattarwork commented on September 14, 2024

So why after all of this discussion the Query method has been removed. Actually having null for predicate is the best idea. @xyting: what is wrong with exposing IQueriable from the repository.

from unitofwork.

alexandru-calinoiu avatar alexandru-calinoiu commented on September 14, 2024

Can this be reoped?

Is still not clear how to get all.

from unitofwork.

farisyusry avatar farisyusry commented on September 14, 2024

just add
IRepository.cs
IQueryable<TEntity> GetAll();

Repository.cs
public IQueryable<TEntity> GetAll() { return _dbSet.AsQueryable(); }

hope can help you

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

In really app, we need GetAll at once? Why not show the paged list for the end user?

from unitofwork.

alexandru-calinoiu avatar alexandru-calinoiu commented on September 14, 2024

@xyting there are a couple of cases where GetAll is usefull, I have a repository to populate dropdowns that have 20 - 30 elements each, I use getpagedlist with a strange 30 for the page size.

from unitofwork.

alexandru-calinoiu avatar alexandru-calinoiu commented on September 14, 2024

@farisyusry I am not sure I understand your answer, can you please elaborate?

from unitofwork.

farisyusry avatar farisyusry commented on September 14, 2024

u just add the code that i give. and u can call this code like this

unitOfWork.GetRepository<User>().GetAll().Where(w=>w.Username == "halo")

its will return querable

from unitofwork.

farisyusry avatar farisyusry commented on September 14, 2024

why i need to use getall?
because i dont want topagedlist. because my query not ready to execute yet. maybe got a lot of line to execute the query.
the best practice for me is return Iquerable by using GetAll. its solve all my problem

from unitofwork.

moattarwork avatar moattarwork commented on September 14, 2024

I guess the whole structure of the paged list is unpleasant in the scenarios which you filter a list and you don't know how many record will be in the result.
Considering that the developer should know the amount of the data which dealing with can be a driver to choose between applying the paging or not, but forcing the paging to every retrieval of the data seems a bit too much.
Currently I'm working on a forked version which works with specification https://en.wikipedia.org/wiki/Specification_pattern or something similar to allow more generality to the Query which I will share afterwards but I think in meantime having IQueryable version would be very beneficial.

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

@moattarwork The IPagedList interface has TotalCount and TotalPages properties.

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

because my query not ready to execute yet. maybe got a lot of line to execute the query.

OK, this is one reason

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

The Query is deprecated because of SHOULD NOT expose the IQueryable out of the Repository, that's to say we want all the database's roundtrip is Repository's internal logic.

This is my original thinking.

from unitofwork.

michelcedric avatar michelcedric commented on September 14, 2024

Wich is your final decision? I waiting GetAll. For the moment I have been getting your projet and add GetAll and recreate my custom nuget package. Will do add GetAll?

from unitofwork.

rigofunc avatar rigofunc commented on September 14, 2024

I had add GetAll method, but I also flag as obsoleted (for warning, will not be removed), see v2.0.2

from unitofwork.

michelcedric avatar michelcedric commented on September 14, 2024

Thanks :)

from unitofwork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.