(CORE) CORE (2024)

C# EF code first. How to create DB context and deploy DB in Net Core 8

I have write a million various instruction about Code first in 2016 years, where EF is appears, for example Entity Framework missing FAQ (Part 1), but all of that instruction was done in more advanced language than C#, on VB.NET. But now I have understand than I have no any instruction on C#. Also .NET Framework core don't need a couple old steps like in .NET Framework 6. Therefore I decide to write this post.

Commonly, this page describe one substep of one of my stupid test task, look for full code on this page C# EF code first Backend API test project


So, firstly we need to create new project, this is absolutely the same as below.




There are one new feature in .NET Core 8 project - Endpoint explorer. This is now needed new function, because all developers has a lot of REST API tools, I like browser extension, if you need to share API you can use more sophisticated tools with functions to share API to other developers. Also this is stupid programs, because usually any test means combine one API with another, for example read how I doing this, for example Simplest way to create tracing and authorization layers in Backend API. Special attribute to arrange API for authorization layers., however MS added this stupid function for full newbie, that's fine.



Next step is create classes to describe DB and create DBContext.



I don't know why, maybe this is my mistake, but in my test project was binding with EF 6 instead EF Core. This was a reason for various issue, therefore I finally delete EF 6 and working with EF Core.



Next steps is configuring connection string.



Next steps is configuring services. This was absolutely stupid project for newbie, therefore MS SQL was used, in reality I newer use MS SQL, I like more advanced SQL server and absolutely free from pay, look any articles in my blog, for example ASP.NET Core Linux, however we add library for Ms SQL (in order to support Microsoft MS SQL sales) and configure options.



Also I usually redefine OnConfiguring method



So, now project is ready and can be compiling



Next step is adding a tools library



And try to add migration.



Migration added, next step is deploy DB and check what we receive in SQL server.



Continue of this test project look in page C# EF code first Backend API test project.



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: http://www.vb-net.com/EF-Test8/Index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>