ASP.NET Core .NET 5 打造WebAPI入門教學(4_2) - 關鍵字搜尋

Leave a Comment

關鍵字讀取api範例
// GET: api/Todo
[HttpGet]
public IEnumerable Get(string name, bool? enable, DateTime? insertTime)
{
   var result = from a in _todoContext.Todos
                select a;

   if (name != null)
   {
      result = result.Where(a => a.Name.IndexOf(name) > -1);
    }

   if (enable != null)
   {
      result = from a in result
               where a.Enable == enable
               select a;
    }

   if (insertTime != null)
   {
      result = from a in result
               where a.InsertTime.Date == insertTime
               select a;
    }

    return result;
}

 範例下載:下載

0 意見:

張貼留言

技術提供:Blogger.