question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem with create method of AsyncCrudAppService

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Jan 8, 2019

Then set it to null.

0reactions
mehdihadelicommented, Jan 8, 2019

Then set it to null.

thanks, it worked.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found