Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Entity Framework Core 2.0

You're reading from   Mastering Entity Framework Core 2.0 Dive into entities, relationships, querying, performance optimization, and more, to learn efficient data-driven development

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788294133
Length 386 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Prabhakaran Anbazhagan Prabhakaran Anbazhagan
Author Profile Icon Prabhakaran Anbazhagan
Prabhakaran Anbazhagan
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Kickstart - Introduction to Entity Framework Core 2. The Other Way Around – Database First Approach FREE CHAPTER 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 Multi-Tenant Database

Performing CRUD operations


We have already seen how to create CRUD operations right from scaffolding controllers to their corresponding views for the Blog model, so we will create them for the Post model in this section:

  1. Right-click on the Controllers folder and select Add | New Scaffolded Item.
  2.  Add Scaffold dialog box, select MVC Controller with views, using Entity Framework:

  1. In the Add Controller dialog box, select the appropriate Model class and Data Context class (Post and MasteringEFCoreDbFirstContext in our case) along with the auto-generated controller name, PostsController:

  1. Next click Add as shown in the following screenshot:

Scaffolded items

Note

The Blog URL should be displayed instead of the Blog ID, which was part of the scaffolding. As displaying the ID raises security issues and usability concerns, let's change this mapping to URL.

Let's start our changes from the Index.cshml file, where we have listed Blog.Id instead of Blog.Url

    @foreach (var item in Model) {
      <tr&gt...
You have been reading a chapter from
Mastering Entity Framework Core 2.0
Published in: Dec 2017
Publisher: Packt
ISBN-13: 9781788294133
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image