It's not completely clear to me what's the diference between using AsNoTracking() on a entity that has a key, and using HasNoKey(). As I understand, when using AsNoTracking(), even though the changetracker does not track changes on the resulting objects, the objects are still kept in the DbContext's memory. If you try to Attach a new object with the same key as one already in memory, you get an error. (correct me if i'm wrong).
So is the behavior the same if you use HasNoKey (former DbQuery<>)?
ModelBuilder.Entity<>().HasNoKey() is one of the breaking changes in
EF Core 3.0 as stated:
A query type now becomes just an entity type without a primary key. Keyless entity types have the same functionality as query types in previous versions.
Query types were a means to query data that doesn't define a primary key in a structured way. That is, a query type was used for mapping entity types without keys (more likely from a view, but possibly from a table) while a regular entity type was used when a key was available (more likely from a table, but possibly from a view).
You said that:
If you try to Attach a new object with the same key as one already in memory, you get an error. (correct me if i'm wrong). So is the behavior the same if you use HasNoKey (former DbQuery<>)?
-Tracking in EF Core transaction are based on Entity Primary key. As the above documentation clearly stating that
QueryType which does not have any key defined. So tracking is completely void in case of
For more details : Query types are consolidated with entity types