I have been blindly following standards laid out from code generated by the RAD tool (which is such a time saver, thanks guys) when I noticed the following method:
[AbpAuthorize(AppPermissions.Pages_Test_Edit)]
private async Task Update(CreateOrEditTestDto input)
{
var test = await _testRepository.FirstOrDefaultAsync((int)input.Id);
ObjectMapper.Map(input, test);
}
This works but I am little confused as to where the update method in the repository is called, I was expecting to see something like:
[AbpAuthorize(AppPermissions.Pages_Test_Edit)]
private async Task Update(CreateOrEditTestDto input)
{
var test = await _testRepository.FirstOrDefaultAsync((int)input.Id);
...
await _testRepository.UpdateAsync(ObjectMapper.Map(input, test));
}
What is the magic with the generated code from the RAD tool? Where is the update called? Can someone point me to some documentation here because this surprised me!
10 Answer(s)
-
0
The magic is change tracking:
Calling Update is unnecessary if the entity is already tracked. In this case, it is tracked since it is retrieved from the repository. For example, another way is to map to a new instance (to replace an entity entirely). In that case, you will have to call Update.
-
0
what is the update on RAD tool new version? You guys promised two weeks back support with foreign key
-
0
hi, navigation property (foreign key support) feature is completed. waiting for other features of AspNet Zero to be completed.
-
0
<cite>alper: </cite> hi, navigation property (foreign key support) feature is completed. waiting for other features of AspNet Zero to be completed.
:lol:
-
0
Hi Aaron, I'm just going to have to go along with you on this one. I've been working with EF for years now (though never with Core before Zero) and always called an update for an update. Even the documentation you referred to explicitly states:
var db = new TestContext(); var book = new Book { BookId = 1 }; db.Update(book); // Book Modified
I don't see how;
ObjectMapper.Map(input, test);
equates to the same thing. The older I get the less I know and the more I realise I have to learn! I will just have to accept that the rabbit came out of the hat even though I know it's impossible....
-
0
It is explained in Unit Of Work documentation.
<a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#automatically-saving-changes">https://aspnetboilerplate.com/Pages/Doc ... ng-changes</a>
-
0
@yekalkan - thanks, I read that too. But I'm still not sure how you pulled all those birds from your hankerchief. It must be magic.... :oops:
-
0
Can I download the updated version today?
-
0
<cite>BobIngham: </cite> Even the documentation you referred to explicitly states:
var db = new TestContext(); var book = new Book { BookId = 1 }; db.Update(book); // Book Modified
That's a case of "For example, another way is to map to a new instance (to replace an entity entirely). In that case, you will have to call Update."
<cite>BobIngham: </cite> I don't see how
ObjectMapper.Map(input, test);
equates to the same thing.
It doesn't. _testRepository.FirstOrDefaultAsync retrieves a tracked entity, new Book creates an untracked entity.
-
0
<cite>faisalalam: </cite> Can I download the updated version today?
You can track progress of v5.3 milestone to get an idea of when it will be released.