I like your GenericRepository that exposes a nice non-db-specific IQueryable interface, but I think it has a subtle bug...
Let's say I am writing an app that lets users add posts and tag them for each others review. I might have a Post class with a TaggedFor property of type ICollection<User>.
So when Alice adds a post and tags it for Bob's review the code might do this..
The User object for Bob is loaded with AsNoTracking(), so when you run Create(post) EF thinks he is a new user, and adds him to the Users table again. Now suppose that your users are identified by their Email field loaded using .Where(u => u.Email == email).Single() then when Alice tags Bob, Bob gets locked out of the site/app. Oops!
I could be wrong since I only have experience with EF 6, but I don't think EF Core is all that different on this point.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like your GenericRepository that exposes a nice non-db-specific IQueryable interface, but I think it has a subtle bug...
Let's say I am writing an app that lets users add posts and tag them for each others review. I might have a
Post
class with aTaggedFor
property of typeICollection<User>
.So when Alice adds a post and tags it for Bob's review the code might do this..
and that's where the bug comes in to play...
The
User
object for Bob is loaded withAsNoTracking()
, so when you runCreate(post)
EF thinks he is a new user, and adds him to theUsers
table again. Now suppose that your users are identified by theirEmail
field loaded using.Where(u => u.Email == email).Single()
then when Alice tags Bob, Bob gets locked out of the site/app. Oops!I could be wrong since I only have experience with EF 6, but I don't think EF Core is all that different on this point.