How to use Transaction in Entity FrameWork?

Posted by programmerist on Stack Overflow See other posts from Stack Overflow or by programmerist
Published on 2010-04-14T14:03:03Z Indexed on 2010/04/14 15:23 UTC
Read the original article Hit count: 174

How to use Transaction in Entity FrameWork? i read some links on Stackoverflow : http://stackoverflow.com/questions/815586/entity-framework-using-transactions-or-savechangesfalse-and-acceptallchanges

BUT; i have 3 table so i have 3 entities:

CREATE TABLE Personel 
(PersonelID integer PRIMARY KEY identity not null, 
Ad varchar(30), 
Soyad varchar(30),
Meslek varchar(100),
DogumTarihi datetime,
DogumYeri nvarchar(100),
PirimToplami 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 my tables. if you look Prim table you can see Prim value float value if i write a textbox not float value my transaction must run.

 using (TestEntities testCtx = new TestEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    // do someyihng...
                    testCtx.Personel.SaveChanges();
                    // do someyihng...
                    testCtx.Prim.SaveChanges();
                    // do someyihng...
                    testCtx.Finans.SaveChanges();
                     scope .Complete();
                        success = true;


                }
            }

How can i do that?

© Stack Overflow or respective owner

Related posts about c#

Related posts about visual-studio-2008