c# - Defining Route for Composite Primary Keys in WebAPI2 -
how can define composite pks in webapi controller? have 2 entities. in 1 of them have 2 primary keys.
the entity "person" has following properties: id (pk), lname (pk), fname, age, groupid (fk).
here controller code:
// get: api/person/5 [httpget] [route("id")] [responsetype(typeof(person))] public async task<ihttpactionresult> getpersonbyid(int id, string lname) { person person = await db.persons.findasync(new object[] {id, lname}); if (person == null) { return notfound(); } return ok(person); }
entity person:
public partial class person { public int id { get; set; } public string lname { get; set; } public string fname { get; set; } public int age { get; set; } public int groupid { get; set; } [foreignkey("id")] public virtual group group { get; set; } }
do have define lname in route dataannotation?
Comments
Post a Comment