c# - How to: Only chosen data retrieving from DB in WebAPI2 and LINQ -


i'm using entity framework , webapi2. ef created model , generated model code. when i'm calling getall method in browser i'm getting whole data structure (with relations other entities). want chosen data displayed in view.

here code getall:

/* entity: qr_name */ /* propertys: id, fname, lname, maxage, groupid */ // get: api/qr_name public iqueryable<qr_name> getallnames() {    return db.qr_names; } 

i've problem when want 1 object of entity. code doesn't work in browser. i'm getting

error message:

the number of supplied primary key values must match number of primary key values defined in entity.

errortype:

"exceptiontype":"system.argumentexception"

that's code id:

// get: api/qr_name/5 [responsetype(typeof(qr_name))] public async task<ihttpactionresult> getnamebyid(int id) {   qr_name name = await db.qr_names.findasync(id); //here comes exception   if (name == null)   {      return notfound();   }    return ok(name); } 


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -