public KeepConnectionAliveScope(DataContext dataContext) { _dataContext = dataContext; _savedValue = dataContext.KeepConnectionAlive; dataContext.KeepConnectionAlive = true; }
public void Add(TM entity) { using (var dataCtx = new LinqToDB.DataContext(ProviderName, ConnectionString)) { try { dataCtx.Insert(entity); dataCtx.BeginTransaction(); } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex.Message); } } }
public void Update(TM entity) { using (var dataCtx = new LinqToDB.DataContext(ProviderName, ConnectionString)) { try { var pkValueRow = (from e in dataCtx.GetTable <TM>() where e.Id.Equals(entity.Id) select e).FirstOrDefault(); dataCtx.Update(entity); dataCtx.BeginTransaction(); } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex.Message); } } }
public TM GetSingle <TP>(TP pkValue) { var pkValueRow = new TM(); using (var dataCtx = new LinqToDB.DataContext(ProviderName, ConnectionString)) { try { pkValueRow = (from e in dataCtx.GetTable <TM>() where e.Id.Equals(pkValue) select e).FirstOrDefault(); } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex.Message); } return(pkValueRow); } }
public long Count() { IQueryable <TM> entities = Enumerable.Empty <TM>().AsQueryable(); using (var dataCtx = new LinqToDB.DataContext(ProviderName, ConnectionString)) { try { entities = dataCtx.GetTable <TM>(); } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex.Message); } return(entities.Count()); } }
public IQueryable <TM> GetAll(Expression <Func <TM, bool> > whereCondition) { IQueryable <TM> entities = Enumerable.Empty <TM>().AsQueryable(); using (var dataCtx = new LinqToDB.DataContext(ProviderName, ConnectionString)) { try { entities = dataCtx.GetTable <TM>().Where(whereCondition); } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex.Message); } } return(entities); }