Cov txheej txheem:

Puas yog Entity Framework txhawb kev kaw qhov tsis zoo?
Puas yog Entity Framework txhawb kev kaw qhov tsis zoo?

Video: Puas yog Entity Framework txhawb kev kaw qhov tsis zoo?

Video: Puas yog Entity Framework txhawb kev kaw qhov tsis zoo?
Video: .Net MVC project with Sql Server and Entity framework step by step 2024, Hlis ntuj nqeg
Anonim

Lwm txoj kev yog mus rau optimistic xauv . Cov ntaub ntawv hais tias EF ua tsis muaj built in pessimistic sib npaug kev txhawb nqa . Tab sis qhov no ua tsis txhais tau tias koj ua tau tsis muaj pessimistic xauv nrog EF. Yog li koj YOG YOG PESIMISTIC LOCKING Nrog EF!

Tsis tas li ntawd, Entity Framework tswj kev sib koom ua ke li cas?

Lub koom haum Framework txhawb kev cia siab sib npaug los ntawm lub neej ntawd. EF txuag 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 raug muab pov tseg thiab koj yuav tsum daws qhov teeb meem ua ntej sim khaws nws dua.

Tsis tas li ntawd, dab tsi yog tus neeg siv khoom yeej thiab lub 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.

Ntawm no, Entity Framework ua li cas los daws cov teeb meem sib txuam?

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.

Web API tswj kev sib koom ua ke 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).

Pom zoo: