コード例 #1
0
 public async Task <int> CountCats()
 {
     using (var db = new CatsContext())
     {
         return(await db.Cats.CountAsync());
     }
 }
コード例 #2
0
 public async Task <List <CatContract> > GetCatsByGender(string gender)
 {
     using (var db = new CatsContext())
     {
         return(await db.Genders.FirstOrDefaultAsync(g => g.Description.Equals(gender, StringComparison.CurrentCultureIgnoreCase))?.ContinueWith(t =>
         {
             if (t.IsFaulted)
             {
                 throw t.Exception;
             }
             return t.Result?.Cats?.Select(c => new CatContract(c)).ToList();
         }, TaskContinuationOptions.OnlyOnRanToCompletion));
     }
 }
コード例 #3
0
 public async Task <CatContract> GetCatByName(string name)
 {
     using (var db = new CatsContext())
     {
         return(await db.Cats.FirstOrDefaultAsync(c => c.Name.ToLower().Equals(name.ToLower())).ContinueWith(t =>
         {
             if (t.IsFaulted)
             {
                 throw t.Exception;
             }
             return new CatContract(t.Result);
         }, TaskContinuationOptions.OnlyOnRanToCompletion));
     }
 }