Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have read some articles that state that IEnumerable used to mimic stored procedures or restrict your database. Lost lazy loading ability on the external provider.

Where as IQueryable to give developers more flexibility. Lazy loading is there.

In terms of performance, both consume a significant amount of performance .. so which one is more preferable?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
427 views
Welcome To Ask or Share your Answers For Others

1 Answer

From the perspective of a Repository Pattern, you can think of it this way:

  1. Use an eager loading IEnumerable when you want to pass an entire list to the client in one go. They can still add linq clauses, but the client does not benefit from deferred execution.

  2. Use a lazy loading IQueryable when you want to extend deferred querying capabilities to the client, by allowing the client to add their own linq clauses. This defers execution of the entire query until output is required.

See Also
Deferred execution and eager evaluation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...