Entity Framework Core Tutorial

Introduction to Entity Framework

Entity Framework is a framework for .NET that provides an object-relational mapping. It simplifies database access and improves code readability.

It allows you to work with databases using objects instead of raw SQL queries, making your code more maintainable.

Creating a Model

To start, you need to create a model class. This class defines the structure of your data.

Example: let's create a simple class:

                class Person {
                    public string Name { get; set; }
                    public int Age { get; set; }
                }
                

Using the DbSet

The `Set` method is used to add, update, or remove data from a DbSet.

Example: `person = person.Set(new Person { Name = "Alice", Age = 30 });`

Using the Query

The `Query` method is used to retrieve data from the DbSet.

Example: `person = person.Query("SELECT * FROM Person");`