c# - Why IEnumerable<T> method call the database without condition? -
this question has answer here:
- what effect of asenumerable() on linq entity? 3 answers
- returning ienumerable<t> vs. iqueryable<t> 15 answers
i have these method in generic repository :
public iqueryable<t> query() { return _dbset.asqueryable(); } public ienumerable<t> enum() { return _dbset.asenumerable(); } if call these method in service layer
_repo.query().where(w => w.isactive == true); _repo.enum().where(w => w.isactive == true); the queryable method call tsql syntax in database, profiler below :
select [extent1].[projectid] [projectid], [extent1].[name] [name], [extent1].[isactivity] [isactivity], [extent1].[isactive] [isactive] [dbo].[project] [extent1] 1 = [extent1].[isactive] which expected, enumerable method select in database without condition, profiler below :
select [extent1].[projectid] [projectid], [extent1].[name] [name], [extent1].[isactivity] [isactivity], [extent1].[isactive] [isactive] [dbo].[project] [extent1] it means enumerable greedily call every record in database including isactive = 0 record. why happening? thought ienumerable suppose deffered means won't until tolist() called.
any appreciated , apologize bad english.
Comments
Post a Comment