Cov txheej txheem:

Entity Framework ua haujlwm li cas?
Entity Framework ua haujlwm li cas?

Video: Entity Framework ua haujlwm li cas?

Video: Entity Framework ua haujlwm li cas?
Video: ORM с нуля | Как устроены Entity Framework и Dapper? | Как реализовать IQueryable? 2024, Kaum ib hlis
Anonim

Lub Koom Haum Ua Haujlwm txhawb kev cia siab sib npaug los ntawm lub neej ntawd. EF saves ib qhov chaw cov ntaub ntawv mus rau lub database, xav tias tib cov ntaub ntawv tsis tau hloov txij li thaum lub qhov chaw tau loaded. Yog tias nws pom tias cov ntaub ntawv hloov pauv, ces qhov kev zam yog muab pov tseg thiab koj yuav tsum daws qhov teeb meem ua ntej sim khaws nws dua.

Ntxiv rau qhov no, Entity Framework tswj kev sib koom ua ke li cas?

Txoj hauv kev dav dav los daws qhov tsis sib haum xeeb yog:

  1. Catch DbUpdateConcurrencyException thaum lub sij hawm SaveChanges.
  2. Siv DbUpdateConcurrencyException.
  3. Rov ua dua qhov tseem ceeb ntawm qhov sib thooj token kom pom cov txiaj ntsig tam sim no hauv cov ntaub ntawv.
  4. Rov sim cov txheej txheem kom txog thaum tsis muaj kev tsis sib haum xeeb.

Tom qab ntawd, lo lus nug yog, Web API ua haujlwm li cas? Yuav ua li cas tuav concurrency hauv ASP. NET Core Web API . Tsim ib qhov project khoob thiab hloov tshiab Startup chav kawm ntxiv cov kev pabcuam thiab nruab nrab rau MVC. Ntxiv ib tus maub los nrog GET thiab PUT los ua qauv qhia sib npaug . Xa daim ntawv thov GET thiab saib ETag header (siv Postman).

Tom qab ntawd, lo lus nug yog, dab tsi yog tus neeg siv khoom yeej thiab khw yeej hom hauv Entity Framework concurrency?

Hauv khw yeej / database yeej cov ntaub ntawv los ntawm lub server yog loaded rau hauv koj qhov chaw khoom. Cov neeg siv khoom yeej yog opposite rau khaws cia yeej , data los ntawm qhov chaw cov khoom raug khaws cia rau hauv database. Peb yuav tsum siv txoj kev "Refresh" ntawm cov koom haum moj khaum cov ntsiab lus thiab peb yuav tsum tau siv "RefreshMode" enum rau tib yam.

Puas yog Entity Framework txhawb kev kaw qhov tsis zoo?

Pessimistic concurrency koom nrog xauv cov ntaub ntawv khaws tseg los tiv thaiv lwm tus neeg siv tuaj yeem nkag mus / hloov pauv mus txog thaum lub xauv yog tso tawm, zoo li thaum ob tus neeg siv sim qhib tib cov ntaub ntawv ntawm lub network sib koom. Lub koom haum Framework Core muab no kev txhawb nqa rau pessimistic concurrency tswj.

Pom zoo: