Example #1
0
 public IQueryable <TEntity> GetAll()
 {
     try
     {
         return(_myDBContext.Set <TEntity>());
     }
     catch (Exception)
     {
         throw new Exception("Couldn't retrieve entities");
     }
 }
Example #2
0
 static void Main(string[] args)
 {
     using (var db = new PersonContext())
     {
         db.Database.Delete();
         //Try to create table
         DbSet per = db.Set<Person>();
         var per1 = new Person { NameId = 1, Name = "James" };
         per.Add(per1);
         int recordsAffected = db.SaveChanges();
         Console.WriteLine(
             "Saved {0} entities to the database, press any key to exit.",
             recordsAffected);
         Console.ReadKey();
     }
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the repository.
 /// </summary>
 /// <param name="context">The context upon which the repository is based.</param>
 public RepositoryBase(PersonContext context)
 {
     _context = context;
     _dbSet   = context.Set <TEntity>();
 }
 public virtual IQueryable <T> getAll()
 {
     return(DbContext.Set <T>().Where(x => x.IsDeleted == false));
 }
Example #5
0
 public IEnumerable <Person> GetAllPerson()
 {
     return(_context.Set <Person>());
 }
Example #6
0
 public void Add(TEntity entity)
 {
     db.Set <TEntity>().Add(entity);
 }
        public IQueryable <PersonEntity> FindBy(Expression <Func <PersonEntity, bool> > predicate)
        {
            IQueryable <PersonEntity> query = dbContext.Set <PersonEntity>().Where(predicate);

            return(query);
        }
Example #8
0
 public GenericRepository(PersonContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
Example #9
0
 public IQueryable <T> GetAll()
 {
     return(_context.Set <T>());
 }