Extra Lazy Loading
When I do user.Cars.Add() EF load all Cars for that user.
Reverting status from “under review” to “no status” since we aren’t currently working on this. We will still consider it for future releases.
Kieron Dye commented
1) Does EntityCollection<T> solve this issue when calling Add()?
2) How can we unit test code that uses EntityCollection<T>.CreateSourceQuery and has no entity context?
It would also be nice if you could filter a relationship without materializing the entire collection. For example:
category.Products.Where(p => p.Brand == "foo");
category.Products.Where(p => p.IsActive);
Having to materialize every item just to retrieve/count a small subset of them can be a huge unnecessary performance hit. If the collection isn't already loaded in memory, it would be great to at least have the option of running the query in the database rather than materializing a bunch of data that isn't being used.
Felipe Fujiy Pessoto commented
I am using Code First, then I need to do this:
Post post = db.Posts.First();
db.Entry(post).Collection(x => x.Categories).Query().Count();
My request is for something like Ayende and Arthur Vickers(MS EF Developer) talk about:
Ladislav Mrnka commented
This is already implemented you just need to call user.Cars.CreateSourceQuery().Count() where Cars must be EntityCollection<Car>.
This would be a nice optional feature to have. In my opinion, EF should not have to load all the cars that belong to the user just to add a new car. The same goes for counting the number of cars that a user owns. EF should not have to load all the cars to get a count, but instead, execute a count query and then return the value.
wouldn't that more accurately called "Extra eager loading"?