EF ICollection Vs List Vs IEnumerable Vs IQueryable

前端 未结 2 981
故里飘歌
故里飘歌 2020-12-12 12:07

so, my EF model has relationships and according to what I have seen in examples, those relationships should be done with virtual properties of ICollection.

Example:<

2条回答
  •  情书的邮戳
    2020-12-12 12:24

    Another difference in case of EF is that the IEnumerable is not executing the query to the DB untill you really enumerate the list. While the IList will execute the query and fetch the items in memory. I had a strange behaviour with caching. Chaching the IEnumarable didn't store the items but rather the unfetched enumeration, everytime i would call the cache and fetch the enumeration for some purpose, it would go to the DB and execute the query, so caching was useless. But a ToList() on the enumeration fetched the items and stored the items in the cache, so only 1 trip to the DB for this. Find more in this post: http://www.dailycode.info/BlogV2/post/entityframework-adding-ienumerable-to-cache

提交回复
热议问题