Entity Framework Migrations Explained

preview_player
Показать описание
The week, James is joined by Brice Lambson, Senior Software Engineer on the Entity Framework team to talk in depth about migrations for your database. When do you need them? How do you run them? How do you maintain them in the long run? Brice breaks it all down.

00:00 - Intro & Brice from the EF Core team
01:30 - What are Database Schema Migrations?
03:40 - Why do I need migrations?
05:20 - Code first or database first?
08:30 - Getting started with EF Core
12:30 - Our first EF Core migration
19:40 - What is in a migration?
22:30 - Remove migrations & required fields
26:00 - Update migrations
32:11 - Running migrations in production
35:20 - Wrap-up, tips & tricks

Links:

#efcore #entityframework #dotnet

Рекомендации по теме
Комментарии
Автор

Really excellent overview of EF migrations. But a word to YouTube content creators... if you say, "Hey, if you have any questions, leave them in the comments below and we'll answer them!", then you should actually do that. None of the questions below have been answered by James or Brice.

timwitort
Автор

This is great. Thank you for covering deployments and not just local development.

chandler
Автор

Thank you, James! I'm following all of your videos even in your channel, they are awesome! Keep going! ;)

JoseSilva-gtzj
Автор

I can't imagine how much I would learn working with Brice. What a smart guy!

willpetersen
Автор

I do have a question...

I've had great success with generating a sql script using Script-Migration command. However when we deploy, the customer would like to know if the number of rows in specific tables have changed before and after a migration. What I've done is manually added SQL statements (ex.
DECLARE @someVariable as int;
SELECT @someVariable = Count(*) FROM Table;
PRINT @someVariable;
GO;
) before the migration and then the same SQL statements at the end.

My question now is, Is there a way to add custom SQL so that it appears at the beginning and/or end of the artifact generated by script-migration?

kjw
Автор

Thank you for this, it's a very good introduction to EF migrations. I have a quick question. Brice mentioned adding a new migration if you're trying to revert a change, but isn't that what the down method is supposed to be used for? If not, when would you use it, just for when you want to revert changes before updating the DB? Thanks again!

bradgermain
Автор

Great info in here. Thank you guys. Brice seems really cool and he's a solid teacher. He reminds me a lot of Scott Hanselman.

liquidpebbles
Автор

Can u create migrations for 2 types of databases at once eg mysql and sqlserver? Say if u have clients using your software but they want to run diff database types due to their environment stack ?

markvl
Автор

Great stuff but I have a question here. When you add any new entity to existing DbContext and then you apply migration, Why it generates all the entities instead of the one which is recently added ? Any idea ?

niravsanghadiya
Автор

It would be also great to know how to tag project version for migrations so we can upgrade from 101.01 to 101.13 passing 01 to 12 changes

SHAMITHADEVINDA
Автор

Anyone has any idea how do migrations work in team environments? When I merge other people's branch to mine, what should the step be to ensure that the migrations I've created and theirs (which happens to be in between) do not conflict? Should I remove my own migration, apply theirs and re-create my own migration again?

AizenSousuke
Автор

Great, when we will see part 2 of EF tutorial? :-)

matteobarbieri
Автор

How to use code first if we want to encrypt columns in a database?

BhanuKorremula
Автор

That [Required] attribute for 'Title' is no longer necessary if you have "Nullable reference types" enabled in C# right? Since the string is non-nullable EF Core would pick that up as nullable: false

divv
Автор

Cool! How do I migrate from the first migration back to nothing in Azure SQL? Assuming that the database has been update with the first migration.

erik
Автор

Why would you ever need to remove a database if UPDATE-database is better? #EntityFramework #DotNet #Csharp

AppAxis
Автор

I see James wheels are turning. Time to update your Monkeys App and Coffee App

ttirrell
Автор

I applied a migration on a production server and it cleared all data...

Автор

that looks like rails migration, ummm, convention over configuration, umm, you've been watching rails' world

haroldpepete