コード例 #1
0
        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();
            }));
        }
コード例 #2
0
 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();
     }));
 }
コード例 #3
0
 public async Task <IEnumerable <T> > Get <T>()
 {
     return(await Task.Run(() =>
     {
         using var db = new LiteDB.LiteRepository(_connectionString);
         return db.Query <T>().ToList();
     }));
 }
コード例 #4
0
 /// <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;
         }
     }
 }
コード例 #5
0
        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();
            }));
        }