Book Image

Mastering Entity Framework Core 2.0

By : Prabhakaran Anbazhagan
Book Image

Mastering Entity Framework Core 2.0

By: Prabhakaran Anbazhagan

Overview of this book

Being able to create and maintain data-oriented 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 row-level 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.
Table of Contents (20 chapters)
Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Dedication
Preface
4
Building Relationships – Understanding Mapping

Chapter 8. Query Is All We Need – Query Object Pattern

 

We have covered raw SQL query execution in Entity Framework (EF), which might be required in a few valid scenarios to have control over queries or to improve performance. We have seen a simple SQL query, the security threat it could pose, and also a solution for this. Then we covered different ways of executing raw SQL queries in Entity Framework.  Finally, we created an extension method to execute raw SQL queries without a DBSet and POCO model.

Let's discuss the repository pattern currently used in the Object Relational Mapping (ORM) layer, looking at its design issues, and we'll see how the query object pattern helps us in achieving this efficiently. The following design issues will be addressed in this chapter:

  • The repository pattern started to abstract the ORM layer, but lately, the methods included in the repository were growing drastically, which defeats its purpose:
    • The necessity to simplify the data access layer led to the query...