Base solution for your next web application
Open Closed

problem with transaction #1574


User avatar
0
omital created

Suppose below app service

public void CreatePerson(CreatePersonInput input)
    {
        var person = new Person { Name = input.Name, EmailAddress = input.EmailAddress };
if(_personRepository.Any().Count()>10)
throw new UserFriendlyExceptio("some error message");
        _personRepository.Insert(person);
   }

based on Abp documentation application service is already implement unitOfWork. but when I send two or more request continuously, exception not fire


8 Answer(s)
  • User Avatar
    0
    omital created

    Does anyone have any idea??

  • User Avatar
    0
    hikalkan created
    Support Team

    I did not understand your question. I also did not understand this code:

    _personRepository.Any().Count()

    Why no just:

    _personRepository.Count()

    ???

  • User Avatar
    0
    omital created

    i'm so sorry. this code

    _personRepository.Any().Count()
    

    is wrong . it is

    _personRepository.Count()
    

    I mean that person's number can not be grater than for example 10.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Why do you expect an exception in this case ?

  • User Avatar
    0
    omital created

    I want to person count can not be bigger than 10

  • User Avatar
    0
    hikalkan created
    Support Team

    Your code seems correct and simple. If it does not work, that means repository.Count() does not work. Can you try to get Count and get list of people to understand if it can not get some people?

  • User Avatar
    0
    omital created

    suppose line

    Syste.Threading.Thread.Sleep(2000);
    

    added before line

    _personRepository.Insert(person);
    

    what happen if client send request rapidly to application service method?

  • User Avatar
    0
    hikalkan created
    Support Team

    If your case is that, why you just add all lines in a lock statement to provide thread synchronization?