EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Query Include Optimized Not Working When I Use AsNoTracking() Method

Open bdjema opened this issue 8 years ago • 9 comments

Hi, When i use IncludeOptimized with AsNoTracking() it's not data appears. var currentModel = db.Users.AsNoTracking() .IncludeOptimized(x=>x.Group) .FirstOrDefault(x=>x.Id == id);

From the above code not working (no "Group" data appears), but if remove AsNoTracking() is working.

Thanks and Regards, Bahar

bdjema avatar Jul 19 '17 04:07 bdjema

Hello @bdjema,

Thank you for reporting.

That is a well-known limitation of our library that we should work on. We already started this fix, I will check during the weekend on much time is left to complete it.

Best Regards,

Jonathan

JonathanMagnan avatar Jul 19 '17 11:07 JonathanMagnan

Hi @JonathanMagnan just wondering if that fix ever materialised for this issue? Thanks!

GFoley83 avatar Feb 26 '18 21:02 GFoley83

Hello @GFoley83 ,

Unfortunately no, we have run into some problem last time we tried.

We are currently focusing our time on the free support on thing such as Fiddle to allow to share only Entity Framework example online: http://www.zzzprojects.com/roadmap

We will probably try again to fix this issue later this year but we have no short time plan for now.

Best Regards,

Jonathan

JonathanMagnan avatar Mar 03 '18 20:03 JonathanMagnan

Hi! Is this issue still present ?

marcbernal avatar Sep 12 '19 15:09 marcbernal

Yes @marcbernal

JonathanMagnan avatar Sep 12 '19 16:09 JonathanMagnan

Looks like this is still an issue more than 4 years after the first report?

bartvanandel avatar Nov 10 '21 11:11 bartvanandel

Hello @bartvanandel ,

Yes, unfortunately, this feature uses the ChangeTracker to set the reference and the AsNoTracking makes it not compatible.

The only way to fix it is either on our side to create a new context internally to handle it automatically (so we will keep tracking entities but simply in a context that will be disposed of right after), or you do the same with a context that you dispose of after.

JonathanMagnan avatar Nov 10 '21 13:11 JonathanMagnan

Thanks for your prompt response!

Currently I've just disabled the .AsNoTracking() calls in our code with a note about incompatibility. For us it's not really a performance penalty at this stage anyway.

The disposable tracker sounds like a promising approach though, especially when provided by the library (less local customization required).

bartvanandel avatar Nov 10 '21 17:11 bartvanandel

Hi, any chance of this being addressed?

dt-karl-kuhn avatar Dec 14 '22 08:12 dt-karl-kuhn