Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Entity framework core seed data

  • kudvenkat
  • 2019-05-01
  • 136900
Entity framework core seed data
  • ok logo

Скачать Entity framework core seed data бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Entity framework core seed data или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Entity framework core seed data бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Entity framework core seed data

In this video we will discuss how to seed database tables with initial data using Migrations in entity framework core.

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
   / @aarvikitchen5572  

Text version of the video
https://csharp-video-tutorials.blogsp...

Slides
https://csharp-video-tutorials.blogsp...

ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...

ASP.NET Core Tutorial
   • ASP.NET core tutorial for beginners  

Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...


If you are using Entity Framework Core 2.1 or later there is a new method of seeding database data. In your application DbContext class, override OnModelCreating() method. In this example, HasData() method configures Employee entity to have the specified seed data.

public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions[AppDbContext] options)
: base(options)
{
}

public DbSet[Employee] Employees { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity[Employee]().HasData(
new Employee
{
Id = 1,
Name = "Mark",
Department = Dept.IT,
Email = "[email protected]"
}
);
}
}

Using Migrations to seed data

The following command adds a new migration. I named the migration SeedEmployeesTable as we are using this migration to specifically add seed data to the Employees database table.

Add-Migration SeedEmployeesTable

Finally, execute Update-Database command to apply the above migration to the database.

Altering Existing Database Seed data

You can alter the existing seed data or add new seed data by adding another new migration.

Step 1 : Modify the code in OnModelCreating() method.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity[Employee]().HasData(
new Employee
{
Id = 1,
Name = "Mary",
Department = Dept.IT,
Email = "[email protected]"
},
new Employee
{
Id = 2,
Name = "John",
Department = Dept.HR,
Email = "[email protected]"
}
);
}

Step 2 : Add a new migration

Add-Migration AlterEmployeesSeedData

Step 3 : Update the database with the latest migration

Update-Database

Keeping DbContext Class Clean

To keep the DbContext class clean, you may move the seeding code from the DbContext class into an extension method on the ModelBuilder class.

using Microsoft.EntityFrameworkCore;

namespace EmployeeManagement.Models
{
public static class ModelBuilderExtensions
{
public static void Seed(this ModelBuilder modelBuilder)
{
modelBuilder.Entity[Employee]().HasData(
new Employee
{
Id = 1,
Name = "Mary",
Department = Dept.IT,
Email = "[email protected]"
},
new Employee
{
Id = 2,
Name = "John",
Department = Dept.HR,
Email = "[email protected]"
}
);
}
}
}

In OnModelCreating() method of the DbContext class, you can then call Seed() method as shown below.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Seed();
}

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]