asp.net web api - Web API using Entity Framework to query by multiple columns -


using ef6, i'm creating web api project. when add controller, entitykey default column queried ("id"), works fine. want add additional columns query within same table via api, i'm unable work.

for example, can query id (/api/ctrlname/123456), if want query via title column, /api/ctrlname?title="value", comes notfound message.

is there simple tutorial set functionality within controller?

    [responsetype(typeof(article))]     public ihttpactionresult getarticle(string id)     {         article article = db.articles.find(id);         if (article == null)         {             return notfound();         }          return ok(article);     }      [responsetype(typeof (article))]     public ihttpactionresult getarticlebytitle(string title)     {         article article = db.articles.find(title);         {             if (article == null)                 return notfound();         }          return ok(article);     }      private bool articleexists(string id)     {         return db.articles.count(e => e.id == id) > 0;     }      private bool articleexiststitle(string title)     {         return db.articles.count(b => b.title.contains(title) ) > 0;     } 

the issue .find() works on primary key. in order work on other columns, must use .where (e.g. db.articles.where(i => i.title.equals(title)).


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -