𝔖 Scriptorium
✦   LIBER   ✦

📁

Mastering Entity Framework Core 2.0: Dive into entities, relationships, querying, performance optimization, and more, to learn efficient data-driven development

✍ Scribed by Prabhakaran Anbazhagan


Publisher
Packt Publishing Limited
Year
2017
Tongue
English
Leaves
376
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Learn how to leverage the features of the new Entity Framework Core APIs and use them to build pure .NET Core applications.

Key Features

  • Learn how to effectively manage your database to make it more productive and maintainable.
  • Write simplified queries using LINQ to acquire the desired data easily
  • Raise the abstraction level from data to objects so teams can function independently, resulting in easily maintainable code

Book Description

Being able to create and maintain dataoriented applications has become crucial in modern programming. This is why Microsoft came up with Entity Framework so architects can optimize storage requirements while also writing efficient and maintainable application code. This book is a comprehensive guide that will show how to utilize the power of the Entity Framework to build efficient .NET Core applications. It not only teaches all the fundamentals of Entity Framework Core but also demonstrates how to use it practically so you can implement it in your software development.

The book is divided into three modules. The first module focuses on building entities and relationships. Here you will also learn about different mapping techniques, which will help you choose the one best suited to your application design. Once you have understood the fundamentals of the Entity Framework, you will move on to learn about validation and querying in the second module. It will also teach you how to execute raw SQL queries and extend the Entity Framework to leverage Query Objects using the Query Object Pattern. The final module of the book focuses on performance optimization and managing the security of your application. You will learn to implement failsafe mechanisms using concurrency tokens. The book also explores rowlevel security and multitenant databases in detail.

By the end of the book, you will be proficient in implementing Entity Framework on your .NET Core applications.

What you will learn

  • Create databases and perform CRUD operations on them
  • Understand and build relationships (related to entities, keys, and properties)
  • Understand inbuilt, custom, and remote validation (both client and server side)
  • You will learn to handle concurrency to build responsive applications
  • You will handle transactions and multitenancy while also improving performance

Who This Book Is For

This book is for .NET Core developers who would like to integrate EF Core in their application. Prior knowledge of .NET Core and C# is assumed.

Table of Contents

  1. Kickstart Introduction to Entity Framework Core
  2. The Other Way Around - Database First Approach
  3. Relationships - Terminology and Conventions
  4. Building Relationships - Understanding Mapping
  5. Know the Validation - Explore Inbuilt Validations
  6. Save Yourself - Hack Proof Your Entities
  7. Going Raw - Leveraging SQL Queries in LINQ
  8. Query Is All We Need - Query Object Pattern
  9. Fail Safe Mechanism - Transactions
  10. Make It Real - Handling Concurrencies
  11. Performance - It's All About Execution Time
  12. Isolation - Building a MultiTenant Database

✦ Table of Contents


Cover
Copyright
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Dedication
Table of Contents
Preface
Chapter 1: Kickstart - Introduction to Entity Framework Core
Prerequisites
Creating a new project
The Start page
The File menu
Structuring the web app
Installing Entity Framework
Data models
[Post entity]
Post entity
Database context
Registering the context in services (.NET Core DI)
Creating and seeding databases
CRUD operations
Summary
Chapter 2: The Other Way Around – Database First Approach
Preparing the database
Blog entity script
Post entity script
Creating  new project
Installing Entity Framework
Reverse engineering the database
Configuring data context
Working with the Blog entity
Working with the Post entity
Registering context in services (.NET Core DI)
Refactoring the OnConfiguring() method
Refactoring the ConfigureServices method
The appsettings.json setting
Performing CRUD operations
Creating controller action
Edit controller action
The Delete view
Summary
Chapter 3: Relationships – Terminology and Conventions
Understanding relationship terms
Data models
Blog entity
The Post entity
Principal entity
Principal key
Dependent entity
Foreign key
Navigation property
Collection navigation property
Reference navigation property
Inverse navigation property
Conventions in a relationship
Fully-defined relationships
Fully-defined relationships - under the hood
No foreign key property
No foreign key property - under the hood
Single navigation property
Foreign key
Inverse property
Summary
Chapter 4: Building Relationships – Understanding Mapping
Relationships
The one-to-one relationship
Building one-to-one relationships using the Fluent API
The one-to-many relationship
The many-to-many relationship
Building many-to-many relationship using the Fluent API
Fluent API
Identifying navigation property and inverse navigation
Identifying the single navigation property
Relationship-building techniques
Building relationship using a foreign key
Building relationships using a principal key
Building relationships using the IsRequired method
Cascade delete
Data migration issue with EF Core 2.0
Summary
Chapter 5: Know the Validation – Explore Inbuilt Validations
Diving into built-in validations
Required field validation
Incorporating the Required validation in blogging system models
EmailAddress field validation
Incorporating EmailAddress validation in blogging system models
Compare field validation
Incorporating the Compare validation in blogging system models
Url field validation
Incorporating Url validation in blogging system models
MinLength field validation
MaxLength field validation
RegularExpression field validation
Summary
Chapter 6: Save Yourself – Hack Proof Your Entities
Client-side validation
Validating data without client-side scripting
Server-side validation
Manual validation
Custom validation
Creating client-side logic for custom validation
Remote validation
Summary
Chapter 7: Going Raw – Leveraging SQL Queries in LINQ
Basic raw SQL queries
Building parameterized queries
Composing with LINQ
Executing SQL query without a DBSet or POCO
Summary
Chapter 8: Query Is All We Need – Query Object Pattern
Introduction to query objects
Improving repositories with the query object pattern
Introduction to repositories
Solution to the repository assignment
Incorporating the query object pattern into repositories
List query object support in the repository
Single query object support in the repository
Solution to the repository with the queries assignment
Composing queries with commands
Solution to the command queries assignment
Enhancing queries with expression trees
Solution to the expression trees assignment
Summary
Chapter 9: Fail Safe Mechanism – Transactions
Default behavior of a transaction
Adding tags support in the blogging system
Leveraging default transaction behavior
Creating a simple transaction
Creating a cross-context transaction
File upload support to the blogging system
Limitations to the transaction scope
Custom transaction scope support
Adding date picker support to the blogging system
Leveraging transactions between multiple technologies
Recent posts support to the blogging system
Anonymous posts list and individual blog post
Listing comments
Adding comments using external database transactions
Summary
Chapter 10: Make It Real – Handling Concurrencies
Handling concurrency in EF
Understanding the concurrency conflicts
Optimistic concurrency
Pessimistic concurrency
Introducing concurrency tokens
Non-timestamp based concurrency tokens
Configuring non-timestamp tokens through data annotation
Configuring non-timestamp tokens through Fluent API
Timestamp-based concurrency tokens
Configuring timestamp tokens through data annotation
Configuring timestamp tokens through Fluent API
Handling concurrency conflicts
Applying optimistic concurrency
Database wins
Client wins
User-specific custom resolution
Applying pessimistic concurrency
Summary
Chapter 11: Performance – It's All About Execution Time
The AsNoTracking() method
How does tracking work?
No-tracking queries
Projections
Detecting changes
Asynchronous operations
Transactions leveraging asynchronous operations
Unnecessary volume returned
The N+1 Select problem
More data than required
Mismatched data types
Missing indexes
Summary
Chapter 12: Isolation – Building a Multi-Tenant Database
Authentication in the blogging system
Row-Level Security
Filter predicate
Block predicate
Multi-tenancy
Standalone
Database-per-tenant
Shared multi-tenant
Dive into multi-tenancy
Blocking cross-tenant write operation
Summary
Index


📜 SIMILAR VOLUMES


Mastering Entity Framework Core 2.0: Div
✍ Prabhakaran Anbazhagan 📂 Library 📅 2017 🏛 Packt Publishing Ltd 🌐 English

Learn how to leverage the features of the new Entity Framework Core APIs and use them to build pure .NET Core applications. About This Book Learn how to effectively manage your database to make it more productive and maintainable. Write simplified queries using LINQ to acquire the desired data easil

Modern Data Access with Entity Framework
✍ Holger Schwichtenberg 📂 Library 📅 2018 🏛 Apress 🌐 English

<p>C# developers, here’s your opportunity to learn the ins-and-outs of Entity Framework Core, Microsoft’s recently redesigned object-relational mapper. Benefit from hands-on learning that will teach you how to tackle frustrating database challenges, such as workarounds to missing features in Entity

Programming Entity Framework: DbContext:
✍ Julia Lerman, Rowan Miller 📂 Library 📅 2012 🏛 O'Reilly Media 🌐 English

The DbContext API captures Entity Framework's (EF) most commonly used features and tasks, simplifying development with EF. This concise book shows you how to use the API to perform set operations with the DbSet class, handle change tracking and resolve concurrency conflicts with the Change Tracker A

Mastering Entity Framework: Effortlessly
✍ Rahul Rajat Singh 📂 Library 📅 2015 🏛 Packt Publishing 🌐 English

Data access is an integral part of any software application. Entity Framework provides a model-based system that makes data access effortless for developers by freeing you from writing similar data access code for all of your domain models. Mastering Entity Framework provides you with a range of op