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

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -