Code First Migration Questions

I have some questions regarding “The Complete ASP.NET MVC5 Course”. I subscribed to your course. I am a beginner ASP.NET

May I please be guided on the following:
a. I tried “enable-migrations” but it showed an error “No context type was found in the assembly.” May I request an explanation of this error and how to resolve it.
b. In the video, under Models folder, there already exist IdentityModels.cs without further explaining how it was created. Is this automatically created when doing “enable-migrations”. If not, can fellow members help and direct me on how to create the model.
c. In your video, under App_Data, a database is automatically created using azure. Can fellow members provide more explanation if this was created automatically using “enable-migrations” and how ? if not, how was it created ?

When the course was created the template had “Individual User Accounts” as the default authentication type. Choosing that scaffolds all the classes needed for Microsoft Identity including a DbContext. Recent versions of the template default to “None” as the authentication type. Likely you didn’t change the current default.

Thank you very much. Will try it.

Hi.

A. It is related to Entity Framework and the important bit is a class deriving DbContext. Identity is not mandatory for that step.

B. There is no Azure in the course (at least when I took it). However you have the possibility to use local database. In such case it will be created in the special folder App_Data. I used to create them manually because without it I had exceptions upon start but I found out there is actually a simple way in VS.

What happens is the default connection string uses local DB and the App_Data special folder is preferred. Now you can find this DB in your Windows profile folder instead. As App_Data and alike do not exist anymore in ASP .NET Core, this is where you’d find the MDF files.

Connection strings doc @MSDN

Regards

Don’t worry about the ‘name space’, I know it’s not ‘Vidly’.
So after ‘enabling migration’ I then started the ‘add-migration InitialModel’ but mine looks completely different than the course’s because I’m using VS 2022 and it doesn’t add the ‘Authentication’ by default. As a result, I do not have the ‘identityModel.cs’… And Mosh has never referenced this model before now… Am I supposed to start the project over?
It’s really irritating when these courses are so outdated…
I’ve included screen shot of my InitialModel code and it’s basically empty…

Hi,
I have been there.

If I remember well the thing was that when Mosh did the course, It added the Individual Identity by default. It was not pointed out and I went in a situation where I wanted to align with the course content.

I did some research and you can actually scaffold some code here and there. Especially some of the Identity Area to get the login pages and alike.

At the time I tried Stack overflow and there was a messy solution being to create a new project with the resources and copy them in the course project.
I later found out there is an assistant (told to be gone) that does this for you in a clean way.

Here is the Stack overflow link where I answered.

Hope this helps you get back on track.

Should you have any other question feel free to ask.

PS : Looking closer at your message, it tells you have a pending migration.
Did you type the Update-Database command ?

Your problem is actually different than mine here (but you’ll get there)
You already tried to add the migration and did not complete the process. The course is for EF6 if I remember well. It is a bit different from how the newer .NET Core works.

When you enable migrations and add a migration it adds some historical data in the project. Just check for the commands depending on what you’d like to do?
Confirm the previous migration or remove it ?