problem with create method of AsyncCrudAppService
See original GitHub issueI have a problem in create method AsyncCrudAppService, in SaveChangeAsync currentUserId set to 0 and in detail exception: The INSERT statement conflicted with the FOREIGN KEY constraint CreatorUserId". The conflict occurred in database “”, table ", column ‘Id’.
while my userId before calling SaveChange is 1. it is weird when I call Create method inner another service method here ‘CreateSuggestion’ and it works correctly.
public class KnowledgeManagementSuggestionAppService: AsyncCrudAppService<KnowledgeManagementSuggestion, KnowledgeManagementSuggestionDto>
{
public KnowledgeManagementSuggestionAppService(IRepository<KnowledgeManagementSuggestion, int> repository) : base(repository)
{
}
public override async Task<KnowledgeManagementSuggestionDto> Create(KnowledgeManagementSuggestionDto input)
{
try
{
var userId = AbpSession.UserId; // 1
var currentTenant = AbpSession.TenantId; //null
var entity = MapToEntity(input);
await Repository.InsertAsync(entity);
await CurrentUnitOfWork.SaveChangesAsync(); //error because CreatorUserId is null
return MapToEntityDto(entity);
}
catch (Exception e)
{
throw e;
}
}
}
public Task<KnowledgeManagementSuggestionDto> CreateSuggestion(KnowledgeManagementSuggestionDto input)
{
return Create(input);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Error when using GetAll (AsyncCrudAppService) and apply ...
1 Answer. GetAll Method From AsyncCrudAppService calls ApplySorting Method, you can override it and there sort as you want.
Read more >ABP CRUD Cheat Sheet: The Distilled, Essential Steps to ...
A quick reference guide for starting the CRUD process from scratch with a new entity in ASP.Net Boilerplate.
Read more >application service documentation
AsyncCrudAppService can get more generic arguments if you want to customize input DTOs for Get and Delete methods. All methods of the base...
Read more >Application Services | Documentation Center | ABP.IO
The CreateAsync method above manually creates a Book entity from given CreateBookDto object, because the Book entity enforces it (we designed it like...
Read more >Questions
Unable to find cause of Client Error!!! · Filter raise issue in Unit Test · CrudAppService and AsyncCrudAppService Classes · Does ABP support...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Then set it to
null
.thanks, it worked.