Q1. LINQ supports two types of query syntaxes—method, which looks like any other method calls in your programming language, and Query, which resembles SQL in its appearance.
Q2. The answer is false. If an entity is tracked by the context after retrieval, all changes are tracked individually. Hence, Entity Framework will create an update query that only includes columns/properties touched by the code after the entity in question was retrieved.
Q3. Only the first property in the sort order is specified by the OrderBy
method; all subsequent ones should be specified by the ThenBy
method calls.
Q4. In order to specify multiple conditions, you need to use logical operators in a single Where
method.
Q5. All of the approaches are valid, although you may find that the AddRange
is a bit more readable.
Q6. The answer is false. Insert
operations are different from other operations. You can add a root entity to its DbSet
, and all child entities are assumed to be in new state as well.
Q7. True, since context was not tracking entities prior to the state being set, context has to assume that all properties have been changed.
Q8. The answer is false. If you want to issue a delete query, you need to attach an entity instead of adding it in order to simulate an existing entity in the unchanged state.
Q9. The detached state corresponds to any entity not tracked by the context. Since it is not tracked, DbContext
will not look at this entity when SaveChanges
is called. Entities in the unchanged state will also not result in any queries, but they are tracked by the context.
Q10. The local property of DbSet
will give you access to in-memory data only and will never result in a database query to look for data.