Hi,
I'm working on adding notifications to our application. All in all things are going fine but I've noticed some strange behaviour appearing.
I noticed that unless I manually call SaveChanges before publishing notifications some fields are no longer automatically set by ABP. These include TenantId, LastModfierUserId and most likely also CreatorUserId. After investigating a bit I found that this happens because the publish notification logic switches to a Host unit of work context and performs a SaveChanges. This leads to tenantId not being available.
I then found documentation stating that tenantId should be manually set which resolves that part of the problem. However, nothing is said regarding LastModifierUserId nor CreatorUserId as far as I can tell.
My question, therefore, is: Is it recommended to call SaveChanges before switching to a host unit of work in order to prevent problems like these?
Thank you
3 Answer(s)
-
0
Hi @atideveloper
This mostly depends on your code. Could you share your code block ?
-
0
We are not really doing anything all that strange. Basically, we are doing something similar to:
public async Task HttpPostService() { EntityImpl item = await repository.Get(id); item.Text = "New text"; notificationPublisher.PublishAsync("EntityChanged",...); }
After we started calling publish async, the LastModifierUserId is no longer set. LastModificationTime is set though. We found it strange that simply adding that one function call lead to this which is why we opened a question. If I add a call to SaveChanges before the publish all values are populated like before.
-
0
Hi,
Yes, in this case, you need to call SaveChanges.