lundi 29 mai 2017

Visual studio web api linq problems

i have a little problem with my controller. I have a database filled with players from fifa (Playersk as key,name and rating). In my playercontroller.cs i can use

// GET: api/Player
        public IEnumerable<Player> Get( )
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            return db.Players;
        }

and

 //GET: api/Player/3
        public Player Get(int id)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            return db.Players.Where(x => x.Playersk == id).FirstOrDefault();
        }

just fine by using http://localhost:63991/xyz. However,i need to use their name and not their id. I'm stuck with this:

//GET: api/Player/Beckenbauer
        public Player Get(string playername)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            return db.Players.Where(x => x.Name.Contains(playername)).FirstOrDefault();
        }

This gives me the same result as the first one,a json/xml(depends on my browser) with the complete table and not a filtered one.

What am i missing?




Aucun commentaire:

Enregistrer un commentaire