public KeepConnectionAliveScope(DataContext dataContext)
		{
			_dataContext = dataContext;
			_savedValue  = dataContext.KeepConnectionAlive;

			dataContext.KeepConnectionAlive = true;
		}
Exemple #2
0
 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);
         }
     }
 }
Exemple #3
0
 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);
         }
     }
 }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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());
            }
        }
Exemple #6
0
        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);
        }