Jak korzystać z transakcji w Entity Framework? Przeczytałem kilka linków na Stackoverflow: Using Transactions or SaveChanges(false) and AcceptAllChanges()?Jak korzystać z transakcji w Entity Framework?
BUT; Mam 3 tabele, więc mam 3 podmioty:
CREATE TABLE Personel
(PersonelID integer PRIMARY KEY identity not null,
Ad varchar(30),
Soyad varchar(30),
Meslek varchar(100),
DogumTarihi datetime,
DogumYeri nvarchar(100),
PirimToplamı float);
Go
create TABLE Prim
(PrimID integer PRIMARY KEY identity not null,
PersonelID integer Foreign KEY references Personel(PersonelID),
SatisTutari int,
Prim float,
SatisTarihi Datetime);
Go
CREATE TABLE Finans
(ID integer PRIMARY KEY identity not null,
Tutar float);
Personel, Prim, Finans moje stoły. Jeśli spojrzysz na tabelę Prim, zobaczysz wartość zmiennoprzecinkową wartości Prim, jeśli napiszę pole tekstowe, a nie wartość zmiennoprzecinkową, którą musi uruchomić moja transakcja.
using (TestEntities testCtx = new TestEntities())
{
using (TransactionScope scope = new TransactionScope())
{
// do something...
testCtx.Personel.SaveChanges();
// do something...
testCtx.Prim.SaveChanges();
// do something...
testCtx.Finans.SaveChanges();
scope.Complete();
success = true;
}
}
Jak mogę to zrobić?
używają 3 różnych kontekstów ... próbujesz zapisać każdą tabelę samodzielnie? – Nix
Masz już kod, z czym potrzebujesz pomocy? – nos
tak chcę dodać 3 tabelę, ale transakcję muszę – programmerist