Entity framework overwriting List works?
I always thought that just overwriting a List like
solution.Skus = [];
doesnt work since the change tracker doesnt update everything, but after some testing it seems to work. Why does everyone then always says to not do this?
13 Replies
Because the old list instance may be held elsewhere.
@wasabi What do you mean by held elsewhere? this is the only code im testing and I tried to clear the changetracker
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
ah so I CAN use ef core like that? I always thought / heared that this is not good for ef core
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View
yea but the problem is its working, when it would expect it to not work, so not really sure how I can find out why that is
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View
it was just a quick example to show what is happening. I just wanted to clear the changetracker to make sure its not some weird cached state behavior
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View
I tried to do it with the asserts, but basically everything is working, but I thought you couldn't just replace a list in ef core. In the example I am replacing the test1.Skus with a completely new list, and everything works (the old skus are getting disconnected, and new ones connected). But all the guides always said to not do this, but to use .Add() .Remove() .Clear()
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View
state tracking is more trouble than it's worth IMO
just assemble your dtos and fire the needed queries
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View