linq - If I expose IQueryable from my service layer, wouldn't the database calls be less if I need to grab information from multiple services? -
if expose iqueryable service layer, wouldn't database calls less if need grab information multiple services?
for example, i'd display 2 separate lists on page, posts
, users
. have 2 separate services provides list of these. if both provides iqueryable, joint in 1 database call? each repository creates context itself.
it's best think of iqueryable<t>
single query waiting run. if return 2 iqueryable<t>
instances , run them in controller, wouldn't different running them separably in own service methods. each time execute iquerable<t>
results, run query independent of other iquerable<t>
objects.
the time (as far know) make impact if there enough time between 2 service calls database connection might close, need considerable amount of time in between service calls case.
returning iquerable<t>
controller still has usefulness, such easier handling of paging , sorting (so sorting done on controller , not done on service layer doesn't care how data sorted or paged). isn't performance concern though, , people disagree if it's best in controller or not (i've seen reputable developers , give thought out reasons why).
Comments
Post a Comment