Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions: how to retrieve ID generated by DB after saveChanges() #65

Open
chaoscn opened this issue Nov 17, 2018 · 2 comments
Open

Comments

@chaoscn
Copy link

chaoscn commented Nov 17, 2018

Hi,

We are using our database to generate ID instead from C# code, that means. The Id of a newly created object is only visible after dbContextScope.SaveChanges() is called. However, the mapping between EF models and domain models already happened in the repository layer which is before saveChanges() been called. This leads to a result that the domain object returned by the add method do not have the ID.
How can I get around this issue?

Thanks,
Chenhao Gao

@chaoscn chaoscn changed the title Suggestions: how to retrieve ID generated after saveChanges() Suggestions: how to retrieve ID generated by DB after saveChanges() Nov 19, 2018
@Ruud2000
Copy link

I am struggling with the exact same issue as well. I noticed in the demo you assign a new Guid to the User Id within the UserCreationSpec which allows you to query based on this Id once created. However, if you let the database generate the ID how do I know which ID to use to query?

@evanlarsen
Copy link

evanlarsen commented Sep 20, 2019

I am having the same issue. Are we supposed to use the AmbientDbContextLocator to grab the dbcontext and then call savechanges from within the repository?

What implications does that have on the outer transaction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants