Entity Framework Core

Sample Code to Create, Read, Update and Delete (CRUD) records, EF Core Many to Many relationship

This article explains how CRUD(Create, read, update, delete) operations can be performed using Entity Framework Core on tables connected through a many-to-many relationship. An asp.net core razor page application is used to demonstrate this.

Configure Many-to-Many Relationships in Entity Framework Core Code First

In RDBMS, we call a relationship between two tables many to many when more than one record in one table is associated with multiple records in the other table. In EF Core 5.0, a many to many relationship can be created without defining a joining table.

Fix: The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program.

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program.Check the spelling of the name, or if a path was included,verify that the path is correct and try again.

Tags:  Troubleshooting

The seed entity for entity type 'X' cannot be added because a non-zero value is required for property 'Id'

In Entity Framework Core, primary key properties are converted to identity columns if the database provider is SQL Server. But when we try to seed a database table with an identity column, the corresponding property value should be provided, as the migration scripts are generated by Entity Framework without connecting to the database.

Tags:  Troubleshooting

Data Annotations in EF Core

.NET provides a set of data annotation attributes that can be used to define constraints to the tables and the columns in the underlying database and override  Entity Framework Core conventions.

Conventions in Entity Framework Core

Conventions are the default rules that control how a model will be mapped to a database schema. Entity Framework core follows these default rules when it is not overridden using Data Annotation Attributes and Fluent API.

Entity Framework Core Migrations

In real-world applications, data models change when new features are added to the application. The model changes have to be propagated to the database to keep the database in sync with the model. Entity Framework Core migrations enable us to incrementally update the changes in the models to the database while preserving the existing data there.

Entity Framework Core DbContext

In simple terms, DbContext is a class in Entity Framework Core that you can inherit in your application and use to access the database and do all the operations there. DbContext can manage database connections, create tables/models and manage their relationships, perform CRUD (create read, update, and delete)operations, track changes, manage transactions, provide first-level caching of objects from the data source, etc.

Installation of Entity Framework Core

Entity Framework Core is not a part of .NET Core. It is available as a Nuget Package that can be added to your project in many ways based on your development environment and the available tools. 

Introduction to Entity Framework Core (EF Core)

Entity Framework Core (EF Core) is an open-source ORM(Object Relational Mapper) framework for .NET applications. An ORM is a framework connecting objects in your application with the tables and fields in a database where the application stores data. Entity Framework Core enables .NET developers to work with a database using .NET objects. It is extensible, lightweight, and supports cross-platform development as it is a part of Microsoft’s .NET Core framework.

Showing 2 of 2