c# - MVC returning entity with foreign key -


new mvc , pretty working backwards through application. have entity, itemtype, has foreign key itemindicator class. i'm creating editable grid has itemtype.code , itemindicator.description in it. when user clicks grid, itemindicator field displays dropdownlist of possible itemindicator.descriptions. in repository, have task returns async task of types follows:

        public async task<pagedresults<itemtype>> getasync(int indid, int skip = 0, int take = -1)     {         pagedresults<itemtype> pagedresults;         try         {             iqueryable<chargetype> query = _dbset.include("indicatordetails");              query = take == -1                 ? query.orderby(i => i.indicatordetails.code)                 : query.orderby(i => i.indicatordetails.code);              var data = await query.tolistasync();              pagedresults = new pagedresults<itemtype>(data, skip, take, data.count);         }         catch (exception e)         {             throw new exception(string.format("could not charge types database. {0}", e.message), e);         }         return pagedresults;     } 

and works, plus understand it. idea include indicator details, includes indicator description need. problem second task:

       public async task<itemtype> getbyidasync(int id)     {         return await _dbset.firstordefaultasync(i => i.id == id);     } 

so first task returns of item types, related description info. need second task pretty same thing, need 1 itemtype it's associated description info. since i'm not expecting more 1 result, should return 1 row, i'm confused how rework expression return itemdescription when id passed in. works in pagedresults task because it's of type iqueryable, not sure how single row.

sorry if seems kind of scattered, learning whole framework @ once. in advance.

you should able use .include , entity make correct connection between itemtype , indicatordetails

public async task<itemtype> getbyidasync(int id) {     return await _dbset.include("indicatordetails").firstordefaultasync(i => i.id == id); } 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -