Comments (27)
Implemented in pull request #18
from unitofwork.
@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.
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.
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.
If we not change the pageSize
, we can use pageSize: int.MaxValue
to get all, but, this is stupid.
from unitofwork.
yes- the null default is the better of those options I reckon!
from unitofwork.
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.
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.
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.
justed commited #22 which changes paged lists to expose items as Queryable's and remove the Obsolete attribute from Query function
from unitofwork.
@Shawson Thanks for your good job!
from unitofwork.
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.
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.
Can this be reoped?
Is still not clear how to get all.
from unitofwork.
just add
IRepository.cs
IQueryable<TEntity> GetAll();
Repository.cs
public IQueryable<TEntity> GetAll() { return _dbSet.AsQueryable(); }
hope can help you
from unitofwork.
In really app, we need GetAll at once? Why not show the paged list for the end user?
from unitofwork.
@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.
@farisyusry I am not sure I understand your answer, can you please elaborate?
from unitofwork.
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.
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.
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.
@moattarwork The IPagedList interface has TotalCount and TotalPages properties.
from unitofwork.
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.
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.
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.
I had add GetAll method, but I also flag as obsoleted (for warning, will not be removed), see v2.0.2
from unitofwork.
Thanks :)
from unitofwork.
Related Issues (20)
- GetPagedListAsync with mapping in selector and includes don't work HOT 1
- SaveChangesAsync(bool ensureAutoHistory = false, params IUnitOfWork[] unitOfWorks)这个怎么使用 HOT 13
- EfCore .30 HOT 3
- EF 3.1 - InsertAsync - Method not found HOT 4
- Update Nuget Please HOT 5
- add in GroupBy HOT 2
- 第一次修改表名会报NullException HOT 1
- 张帅,把范型仓储直接注入到容器吧
- UnitOfWork中SaveChangesAsync两个重载很歧义啊 HOT 1
- Add custom method to a custom repository HOT 2
- 分表操作:第一次调用仓储对象的ChangeTable指定新表时就报这样的错,但是第二次就不会报错,每次都是在运行项目后第一次调用时报错 System.NullReferenceException:“Object reference not set to an instance of an object HOT 5
- GetPagedList orderBy parameter HOT 2
- hi, do you have any plan for EF .NET 5.0? HOT 6
- Is it worth to add plain List() methods other than Page? HOT 2
- 当我们用unitOfwork时, 怎么避免不同的线程操作?
- Microsoft.Extensions.Logging.ILoggingBuilder HOT 6
- did you stopped updating this repo? HOT 7
- how to use Auto Include HOT 1
- NuGet package 3.1.0 does not support .NET 6
- Add DI scope override HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitofwork.