c# - Returning newly-added record in EFcore -


i doing prototype using efcore , struggling way return object i've added collection on entity.

for example:

public songleader addsongleader(int congregationid, songleader songleader) {     var congregation = _dbcontext.congregations.include(c => c.songleaders).firstordefault(c => c.id == congregationid);     congregation.songleaders.add(songleader);                             _dbcontext.savechanges();      //todo: return recently-added record...     return null; } 

a congregation has collection of songleaders. once save context, though, i'm not sure of way return new instance. id of songleader generated when it's inserted db can't return object passed method...

is there strategy or baked ef in scenario?

you can return songleaders caller or integer value return savechanges() method. depend on requirements you.

from controller can use createdatroute method return response.

here tutorial can read. mention http recommendation rest api.

building first web api asp.net core mvc


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -