コード例 #1
0
 public T Get(Expression <Func <T, bool> > expression)
 {
     try
     {
         using (_context = new LapContext())
         {
             return(_context.Set <T>().FirstOrDefault(expression));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.GetAll ; Repository", ex);
     }
 }
コード例 #2
0
 public T Get(object Id)
 {
     try
     {
         using (_context = new LapContext())
         {
             return(_context.Set <T>().Find(Id));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.Get ; Repository", ex);
     }
 }
コード例 #3
0
 public List <T> GetAll(Expression <Func <T, bool> > expression)
 {
     try
     {
         using (_context = new LapContext())
         {
             if (expression == null)
             {
                 return(_context.Set <T>().ToList());
             }
             return(_context.Set <T>().Where(expression).ToList());
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.GetAll ; Repository", ex);
     }
 }
コード例 #4
0
 public List <T> GetAllIncluding(params object[] includeProperties)
 {
     try
     {
         using (_context = new LapContext())
         {
             IQueryable <T> query = _context.Set <T>();
             foreach (var includeProperty in includeProperties)
             {
                 query = query.Include(includeProperty.ToString());
             }
             return(query.ToList());
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.GetAllIncluding ; Repository", ex);
     }
 }
コード例 #5
0
 public CResult <T> BulkInsert(List <T> obj)
 {
     try
     {
         using (_context = new LapContext())
         {
             _context.Set <T>().AddRange(obj);
             _context.SaveChangesAsync();
             return(new CResult <T>()
             {
                 Object = null, Succeeded = true, Desc = "Kayıt işlemi başarılı."
             });
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.BulkInsert ; Repository", ex);
     }
 }
コード例 #6
0
 public T GetIncluding(Expression <Func <T, bool> > expression, params Expression <Func <T, object> >[] includeProperties)
 {
     try
     {
         using (_context = new LapContext())
         {
             IQueryable <T> query = _context.Set <T>();
             foreach (var includeProperty in includeProperties)
             {
                 query = query.Include(includeProperty);
             }
             return(query.FirstOrDefault(expression));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.GetIncluding ; Repository", ex);
     }
 }
コード例 #7
0
 public virtual List <T> GetAllIncluding(params Expression <Func <T, object> >[] includeProperties)
 {
     try
     {
         using (_context = new LapContext())
         {
             IQueryable <T> query = _context.Set <T>();
             foreach (var includeProperty in includeProperties)
             {
                 query = query.Include(includeProperty);
             }
             return(query.ToList());
             // return query.AsNoTracking();//, AsNoTracking kullanırsak yaptığımız select üzerinde herhangi bir update işlemi uygulayamıyoruz.
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Repository.GetAllIncluding ; Repository", ex);
     }
 }
コード例 #8
0
 public CResult <T> Add(T obj)
 {
     try
     {
         using (_context = new LapContext())
         {
             _context.Set <T>().Add(obj);
             _context.SaveChanges();
             return(new CResult <T>()
             {
                 Object = obj, Succeeded = true, Desc = "Kayıt işlemi başarılı."
             });
         }
     }
     catch (Exception ex)
     {
         return(new CResult <T>()
         {
             Succeeded = false, Desc = ex.Message.ToString(), ex = ex
         });
     }
 }
コード例 #9
0
 public CResult <T> Update(T obj)
 {
     try
     {
         using (_context = new LapContext())
         {
             _context.Entry(obj).State = EntityState.Modified;
             _context.SaveChanges();
             return(new CResult <T>()
             {
                 Object = obj, Succeeded = true, Desc = "Güncelleme işlemi başarılı."
             });
         }
     }
     catch (Exception ex)
     {
         return(new CResult <T>()
         {
             Object = obj, Succeeded = false, Desc = ex.Message.ToString(), ex = ex
         });
     }
 }
コード例 #10
0
 public CResult <string> Delete(object Id)
 {
     try
     {
         using (_context = new LapContext())
         {
             var item = _context.Set <T>().Find(Id);;
             _context.Set <T>().Remove(item);
             _context.SaveChanges();
             return(new CResult <string>()
             {
                 Succeeded = true, Desc = "Silme işlemi başarılı."
             });
         }
     }
     catch (Exception ex)
     {
         return(new CResult <string>()
         {
             Succeeded = false, Desc = ex.Message.ToString()
         });
     }
 }
コード例 #11
0
ファイル: Repository.cs プロジェクト: omer41/Katmanli-Mimari
 public Repository(LapContext context)
 {
     _context = context;
     dbSet    = _context.Set <T>();
 }