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

In my query i need to return IEnumerable but i dont know if this action make the query to execute again?

var data = Repository<Person>.Find().AsEnumerable();

Find() returns IQueryable and because IQueryable inherits IEnumerable. I doubt if AsEnumerable make the repetitive execution.

I know that var data = Repository<Person>.Find().ToList() executes the query two times. One for Find() and second for Tolist()

See Question&Answers more detail:os

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

1 Answer

An IQueryable is an IEnumerable. There is no conversion, and therefore no work of any kind going on.

The work happens when you call GetEnumerator(), either explicitly or by invoking foreach on it.

Also, have you confirmed that Repository.Find().ToList() calls SQL twice? That doesn't sound right to me.


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