lundi 7 novembre 2016

i want to get all the records of the names that begin with a particular letter, using mvc 4 asp web api

[Route("api/Student/{name}")] public HttpResponseMessage Get(string name)

    {
        using (studentContext sc = new studentContext())
        {
            var entity = sc.Students.Where(x => x.Name.StartsWith(name)) ;

            if (entity != null)
            {
                return Request.CreateResponse(HttpStatusCode.OK, entity);
            }

            else
            {
                return Request.CreateResponse(HttpStatusCode.NotFound, "Staff with name:" + name.ToString() + "not found");
            }
        }


    }




Aucun commentaire:

Enregistrer un commentaire