public string Add(T model) { model.ID = Guid.NewGuid(); db.Set <T>().Add(model); db.SaveChanges(); return("Veri Eklendi"); }
public async Task <bool> Delete(int id) { using (ProjectDbContext context = _context.CreateDbContext()) { var deleteEntity = await context.Set <User>().FirstOrDefaultAsync(a => a.Id == id); if (deleteEntity != null) { context.Set <User>().Remove(deleteEntity); return(true); } return(false); } }
public virtual SaveResult<T> Add(T entity) { var output = new SaveResult<T>(); if (entity.Id != default) throw new Exception("la entidad ya tiene id"); entity.Id = Guid.NewGuid(); _dbContext.Set<T>().Add(entity); _dbContext.SaveChanges(); output.IsSuccess = true; output.Entity = entity; return output; }
public TestConnection() { _connection = new SqliteConnection("datasource=C:\\Users\\jordi\\source\\repos\\ProjecteMVVMWPFNou\\ProjecteMVVMWPFNou\\ProjecteFinalMVVM.db"); _connection.Open(); _options = new DbContextOptionsBuilder() .UseSqlite(_connection) .Options; using (var context = new ProjectDbContext(_options)) context.Database.EnsureCreated(); using (var context = new ProjectDbContext(_options)) { var nopuedorr = context.Database.CanConnect(); var provider = context.Database.ProviderName; var student = new Student() { Dni = "12345DniTest", Name = "Nombre de Test", ChairNumber = 26, }; context.Set <Student>().Add(student); context.SaveChanges(); } _connection.Close(); }
public async Task <User> Get(int id) { using (ProjectDbContext context = _context.CreateDbContext()) { var getEntity = await context.Set <User>().FirstOrDefaultAsync(a => a.Id == id); return(getEntity); } }
public async Task <List <User> > GetAll() { using (ProjectDbContext context = _context.CreateDbContext()) { var allEntity = await context.Set <User>().ToListAsync(); return(allEntity); } }
public async Task <User> GetByUserName(string name) { using (ProjectDbContext context = _context.CreateDbContext()) { var getEntity = await context.Set <User>().Where(a => a.Name == name).Include(a => a.Provider).Include(a => a.Deliverys).FirstOrDefaultAsync(); return(getEntity); } }
public List <TEntity> GetAll(Expression <Func <TEntity, bool> > predicate = null) { var query = _context.Set <TEntity>().IgnoreQueryFilters().AsNoTracking(); return(predicate == null ? query.ToList() : query.Where(predicate).ToList()); }
public async Task <Provider> Create(Provider entity) { using (ProjectDbContext context = _context.CreateDbContext()) { var newEntity = await context.Set <Provider>().AddAsync(entity); await context.SaveChangesAsync(); return(newEntity.Entity); } }
public async Task <User> Create(User entity) { using (ProjectDbContext context = _context.CreateDbContext()) { var newEntity = await context.Set <User>().AddAsync(entity); context.Entry(entity.Provider).State = EntityState.Unchanged; await context.SaveChangesAsync(); return(newEntity.Entity); } }
public async Task <User> Update(int id, User entity) { entity.Id = id; using (ProjectDbContext context = _context.CreateDbContext()) { var updateEntity = context.Set <User>().Update(entity); await context.SaveChangesAsync(); return(updateEntity.Entity); } }
public Task <int> AddAsync <TEntity>(TEntity entity) where TEntity : class { try { DbEntityEntry entityEntry = _context.Entry(entity); if (entityEntry.State != EntityState.Detached) { _context.Set <TEntity>().Attach(entity); } else { _context.Set <TEntity>().Add(entity); } return(Task.FromResult(1)); } catch (Exception e) { throw e; } }
public IEnumerable <TEntity> GetAll() { try { var query = context.Set <TEntity>().AsNoTracking().AsQueryable(); return(query); // return Set.ToList(); } catch (Exception ex) { throw ex; } }
//Singleton.Context yazildiginda Singleton class'inin icerisindeki Context propertysini cagirmis oluyoruz.Bu property kullanilacak eger daha once herhangi bir instance alinmadi ise yani _context olan property'nin ici bos ise, ProjectDbContext'en yani Singleton ile bir instance alinmadiysa, ilk instance i yolluyor eger baska bir yerde alindiysa bu property (Singleton.Context) ve dolayisiyla (Singleton._context) static olarak kalacagi icin if dongusune girmeyip _context i yollayacak ki bu da onceden ici doldurulmus new ProjectDbContext olacak. Yani ProjectDbContext in instance ini almamiza yarayan diger parca. public string Add(T model) { try { db.Set <T>().Add(model); db.SaveChanges(); return("Veri Eklendi"); } catch (Exception ex) { return(ex.Message); } }
public bool Add(TEntity entity) { try { using (var _context = new ProjectDbContext()) { _context.Set <TEntity>().Add(entity); var res = _context.SaveChanges(); return(res > 0); } } catch (DbEntityValidationException e) { throw e; } catch (Exception ex) { return(false); } }
public virtual IEnumerable <T> GetAll() { return(context.Set <T>()); }
public virtual T CreateElement(T element) { return(dbContext.Set <T>().Add(element).Entity); }
public Repository(ProjectDbContext dbContext) { _dataContext = dbContext; Dbset = _dataContext.Set <TEntity>(); }
public Repository(ProjectDbContext DataContext) { _dataContext = DataContext; _dbset = DataContext.Set <T>(); }
public AccountRepository(ProjectDbContext context) { _context = context; _dbSet = context.Set <LEntity>(); }
public ICollection <TModel> Read() { return(_dbContext.Set <TModel>().ToList()); }
public Task <TEntity> GetAsync <TEntity>(int id) where TEntity : class { return(_context.Set <TEntity>().FindAsync(id)); }
public Repository(ProjectDbContext Context) { context = Context; _dbSet = context.Set <TEntity>(); }
public async virtual Task CreateAsync(T item) { await _database.Set <T>().AddAsync(item); await _database.SaveChangesAsync(); }
public void Add(T model) { model.ID = Guid.NewGuid(); db.Set <T>().Add(model); db.SaveChanges(); }
// CR(U)D public void Create(TEntity entity) { _context.Set <TEntity>().Add(entity); }
public GenericRepository(ProjectDbContext context, IUnitOfWork uow) { this.context = context; this.dbSet = context.Set <TEntity>(); _uow = uow; }
public Repository(ProjectDbContext DataContext, UserContext userContext) { _dataContext = DataContext; _dbset = DataContext.Set <T>(); _userContext = userContext; }
public Respository() { _ctx = new ProjectDbContext(); tbl = _ctx.Set <TEntity>(); }
public Repository(ProjectDbContext context) { Context = context; Entities = context.Set <TEntity>(); }