public async Task <T> Get <T>(Guid id, bool isNullable = true) where T : IEntity { return(await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); if (isNullable) { return db.Query <T>().Where(e => e.Id == id).FirstOrDefault(); } return db.Query <T>().Where(e => e.Id == id).Single(); })); }
public async Task <IEnumerable <T> > Get <T>(Expression <Func <T, bool> > predicate) { return(await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); return db.Query <T>().Where(predicate).ToList(); })); }
public async Task <IEnumerable <T> > Get <T>() { return(await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); return db.Query <T>().ToList(); })); }
/// <summary> /// Find customer from database by id. /// </summary> /// <param name="id"></param> /// <returns></returns> public Customer Read(Guid id) { using (var repo = new LiteDB.LiteRepository(ConnectionString)) { try { return(repo.Query <Customer>().Where(x => x.Id == id).First()); } catch (DbException e) { throw e; } } }
public async Task <T> Get <T>(Expression <Func <T, bool> > predicate, bool isNullable) { if (isNullable) { return(await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); return db.Query <T>().Where(predicate).FirstOrDefault(); })); } return(await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); return db.Query <T>().Where(predicate).Single(); })); }