Cov txheej txheem:

Kuv yuav tshem tawm EF tsiv teb tsaws chaw li cas?
Kuv yuav tshem tawm EF tsiv teb tsaws chaw li cas?

Video: Kuv yuav tshem tawm EF tsiv teb tsaws chaw li cas?

Video: Kuv yuav tshem tawm EF tsiv teb tsaws chaw li cas?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim

Tshem tawm a kev tsiv teb tsaws chaw

Qee zaum koj ntxiv ib kev tsiv teb tsaws chaw thiab paub tias koj yuav tsum tau hloov pauv ntxiv rau koj EF Core qauv ua ntej siv nws. Rau tshem tawm kawg kev tsiv teb tsaws chaw , siv cov lus txib no. Tom qab tshem tawm tus kev tsiv teb tsaws chaw , koj tuaj yeem ua tus qauv hloov pauv ntxiv thiab ntxiv nws dua.

Kuj tseem paub yog, EF tsiv teb tsaws chaw ua haujlwm li cas?

Cov kev tsiv teb tsaws chaw feature tso cai rau koj hloov pauv rau koj tus qauv thiab tom qab ntawd nthuav tawm cov kev hloov pauv rau koj cov schema database. Kev tsiv teb tsaws chaw yog enabled los ntawm default hauv EF Core. Lawv raug tswj los ntawm kev ua cov lus txib. Yog tias koj muaj Visual Studio, koj tuaj yeem siv Pob Tus Thawj Tswj Console (PMC) los tswj kev tsiv teb tsaws chaw.

Ib yam li ntawd, ntxiv kev tsiv teb tsaws ua dab tsi? Ntxiv - Kev tsiv teb tsaws chaw : Tsim ib qho tshiab kev tsiv teb tsaws chaw chav kawm raws li teev npe nrog Up() thiab Down() txoj kev. Hloov tshiab-Database: Ua qhov kawg kev tsiv teb tsaws chaw cov ntaub ntawv tsim los ntawm cov Ntxiv - Kev tsiv teb tsaws chaw hais kom ua thiab siv cov kev hloov pauv rau database schema.

Hais txog qhov no, kuv yuav rov kho kuv txoj kev tsiv teb tsaws chaw li cas?

Scenario 1:

  1. Tshem tawm tag nrho cov ntaub ntawv tsiv teb tsaws chaw hauv koj qhov project. Mus los ntawm txhua qhov ntawm koj qhov project apps tsiv teb tsaws chaw thiab tshem tawm txhua yam hauv, tshwj tsis yog cov ntaub ntawv _init_.py.
  2. Tso cov ntaub ntawv tam sim no, lossis tshem tawm db. sqlite3 yog tias nws yog koj li.
  3. Tsim cov thawj migrations thiab tsim cov database schema:

Kuv yuav pab tau migration li cas?

Xaiv Cov Cuab Yeej> NuGet Pob Tus Thawj Tswj> Pob Tus Thawj Tswj Console. Cov Pab - Kev tsiv teb tsaws chaw txib tsim cov Kev tsiv teb tsaws chaw folder, uas muaj ib tsab ntawv los pib lub database. Qhib Configuration. cs file hauv Kev tsiv teb tsaws chaw nplaub tshev.

Pom zoo: