Using EF 6, I'm making a web API project. When I add a controller, EntityKey is the default column query ("id"), which works fine. I want to add additional columns to query the same table via API, which I am unable to work in.
For example, I can query ID (/ api / CtrlName / 123456), but if I have a title column, / api / CtrlName? If you want to query through title = "value", then it always comes back with a notfound message.
Is there a simple tutorial for setting this functionality controller? [ResponseTip (typewrite)] Public IHttpActionResult GetArticle (String ID) {Article Article = db.Articles.Find (id); If (article == zero) {return NotFound (); } Refund (article); } [ResponseTip (typef (paragraph))] Public IHttpActionResult GetArticleByTitle (String title) {Article Article = db.Articles.Find (title); {If (article == zero) returns NotFound (); } Refund (article); } Personal Bull ArticleExists (String ID) {Return db.Articles.Count (E => EID == ID) & gt; 0; } Private Boole ArticleExistsTitle (String title) {return db.Articles.Count (b => b.title.Contains (title)) & gt; 0; }
The problem is that. () Works only on the primary key to work on other columns, you have to use. Where (such as db.Articles.Where (i => i.Title.Equals (title)).
No comments:
Post a Comment