.NET Framework

Database transaction using LINQ

Y2K 2009. 1. 7. 11:03

System.Transaction 을 reference로 추가

System.Data쪽에 없는 것이 약간 이상하다.;


using ( TransactionScope ts = new TransactionScope() )
{
    try
    {
        Customer customer = ( from c in syncMailDB.Customers where c.ID == updateUser.CustomerPK select c ).First();

        customer.LOGONNAME = updateUser.SamAccount;
        customer.NAME = updateUser.Name;
        customer.DIAPLAYNAME = updateUser.DisplayName;
        customer.STATE = updateUser.State;
        customer.PHONEPIN = updateUser.UserPIN;
        customer.EMAIL = updateUser.EmailAddress;
        
        customer.UPDATETIME = DateTime.Now;
        syncMailDB.SubmitChanges();
        
        ts.Complete();
    }
    catch ( Exception ex )
    {
        return false;
    }
}
return true;