Part II (closed) Flashcards
How can EF react when adding multiple objects and an error occurs?
On saving changes EF detects that the bad insert item is not inserted and tries to add it once again and throws an error. A solution is to create a new dbcontect (brute force) or mark the bad item state as detached. In case of changed items (updated or deleted) state should be changed to unchanged.
How to you SaveChanges in EF in context of adding items?
When considering only a few inserts SaveChanges can be invoked after every insert, when bulk only once.
Why is maximum request length defined in ASP.NET?
To avoid DoS (Denial of Service) attack.
How is relationship many-to-many called when the joining table has additional data?
Many-to-many join with payload.
What is a database sharding?
A way of splitting databases and improving performance. Similar to horizontal partitioning but instances can exist independently (smaller tables are duplicated).
Horizontal partitioning vs vertical partitioning?
Horizontal is dividing data while vertical is dividing schema.
What is an N+1 problem?
A problem in which in a relationship 1-to-many (e.g. car and wheels) we want to get for a set of items all its children then N+1 queries can be generated, to avoid this we can load all children to memory and then join it. In EF it can be solved by eager loading using Include.
SOAP vs REST?
REST is simpler, without contract, should be controlled by HATEOAS, no backup for security, uses HTTP POST, GET, DEL, PUT, different formats
SOAP is heavier, it serves WS-Security, WS-ReliableMessaging, WS-AtomicTransaction, provides contract, uses HTTP POST, only XML
What is Liskov substitution principle?
That classes derived from abstractions should be used everywhere where abstraction without affecting application. For example Store, StandardMessageStore and RotatingStore which deletes some messages. Then getMessages won’t retrieve all messages.
Compare Inversion of Control, Dependency Inversion and Dependency Injection?
Inversion of control, inverts program flows because custom code is called by some framework, Dependency Injection helps IoC achieve this goal. Dependency Inversion is about references -> high level module and low level modules should depend on abstractions.
Compare Read Committed, Repeatable Read and Serializable?
RC ensures that all data is committed, future read can bring different results, RR guarantees that future reads will show exactly the same data while SR guarantees that no new data is inserted.
Main ways of structuring view model and model in ASP.NET MVC?
Inheritance, composition, duplication of code.
What’s the convention for naming partial views in ASP.NET?
To start with underscore _ and suffix with “Partial”
What data models are there in EF?
Conceptual, logical, physical.
Main approaches to data in EF?
Model-first (designer generates DB and domain classes), database-first (designer, generates domain classes), code-first (code, migrations).
What object hold all the information required to query database and map to entity objects and what are its main parts?
EDM (Entity Data Model) which is created in memory holds:
- conceptual model: domain classes, context class, configuration
- storage model: information about db schema
- mappings: mapping between conceptual and storage
What is the Object Service in EF?
A part of EF responsible for talking with database, especially materializing queries (converting query’s result to entity objects.
What is Entity Client Data Provider in EF?
A part of EC responsible for transalting LINQ to Entities query or Entity Sql Query to SQL.
What represents a session with the underlying database in EF?
DbContext
What is an entity in EF, what are type of entity’s properties?
A class that can be used with DbSet and relates to single table in a database. Its properties reference columns of this table. There are two types of entities properties:
- Scalar Property (single value, column)
- Navigation Property:
- Reference Property,
- CollectionProperty
What is a POCO class?
Plain Old CLR Object - a class that doesn’t contain any framework-specific elements, doesn’t derive from any specific base class.
What are 2 types of entities in EF?
POCO, POCO Proxy (dynamic proxy) which enables lazy loading, but POCO class must fullfil some requirements .
Which state conversion is handled automatically by EF context?
From Unchanged to Modified.
What are persistence scenarios in EF?
Connected, disconnected
What is OCC (Optimistic Concurrency Control)?
A way of maintaining concurrency in which there are no locks but each transaction does its work but before commiting it checks if another transaction made any changes. If yes it restarts itself and tries again. Good for low data contention systems. Pessimistic concurrency relates to locking methods.
How to improve performance in EF while getting read-only properties?
Use AsNoTracking on DbSet.
What kind of joining table is supported in EF without the need for creating additional model class and managing it?
Joining table without payload.
How to retrieve in SQL number of rows affected by last statement?
Using @@ROWCOUNT
Compare Data Driven Dev with Domain Driven Dev?
In DDD you should first create domain model without database. The best way is to create it without database, use TDD and create an application. Only then you should create a database but using the repository pattern to introduce abstraction.
In Data Driven Dev you first create your database and your model reflects that database and operations on it -> CRUD.