Open Closed

creating a 1 to many relationship entity in MongoDB giving error. #1416


User avatar
0
Neozzz created

We have a collection called Company with properties like name, address etc. Then we have a collection called CompanyBranch with properties:

public Guid CompanyId { get; set; } public string BranchName { get; set; } public Address Address { get; set; }

Where the id of the initial collection called "Company" will be stored in "CompanyId" property of the "CompanyBranch" collection.

There is a one to many relationship between company and companyBranch where 1 company can have multiple companyBranches.

The CompanyBranch app service code to create a companyBranch entity is as follows:

  • SolutionName.Application/CompanyBranches
namespace SolutionName.CompanyBranches
{
        private readonly ICompanyRepository _companyRepository;
        private readonly ICompanyBranchRepository _companyBranchRepo;
        private readonly CompanyBranchManager _companyBranchManager;

        public CompanyBranchAppService(
            ICompanyBranchRepository companyBranchRepo,
            ICompanyRepository companyRepository,
            CompanyBranchManager companyBranchManager)
        {
            _companyBranchManager = companyBranchManager;
            _companyBranchRepo = companyBranchRepo;
            _companyRepository = companyRepository;
        }

        #region CREATE
        public async Task<CompanyBranchDto> CreateAsync(CreateUpdateCompanyBranchDto input)
        {
            var branch = await _companyBranchManager.CreateAsync(                
                input.BranchName,
                input.CompanyId,
                input.Address);

            var companyBranchDto = ObjectMapper.Map<CompanyBranch, CompanyBranchDto>(branch);
            companyBranchDto.CompanyName = await _companyRepository.FindByIdAsync(branch.CompanyId);
            await _companyBranchRepo.InsertAsync(branch);
            
            return companyBranchDto;
        }
        #endregion
}

The error response on executing the create api looks like this:

Trying to put the breakpoint I am not able to get any response from visual studio, the request just finishes with the error without pausing. Please let me know where the issue might be.

Thank you.


10 Answer(s)
  • User Avatar
    0
    Neozzz created

    hi. please update. thank you.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can you share the error stack? thanks.

  • User Avatar
    0
    Neozzz created

    Hi,

    Can you share the error stack? thanks.

    { "userId": "dcf37353-fc1d-0bb5-e820-39fc86c50a1e", "userName": "admin", "tenantId": null, "impersonatorUserId": null, "impersonatorTenantId": null, "executionTime": "2021-06-01T07:19:20.16Z", "executionDuration": 5, "clientIpAddress": "::1", "clientName": null, "browserInfo": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66", "httpMethod": "POST", "url": "/api/app/company-branch", "exceptions": "", "comments": "", "httpStatusCode": 500, "applicationName": null, "correlationId": "6625a18b1f1747a7a1fdb7e7664ccfab", "entityChanges": [], "actions": [], "id": "e6ecd896-becd-ad49-8f8c-39fcd89dc565", "extraProperties": {} }

    Please let me know if this is what you wanted.
    Thank you
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I mean the application error log : ).

  • User Avatar
    0
    Neozzz created

    Hi,

    I mean the application error log : ).
    Hi, Please find the below link to the log file in the httpapi.host project.

    https://commitme-my.sharepoint.com/:t:/g/personal/naeem_comm-it_com_sa/Eb8xKWHKJ6tNvmx3KaVc57gBPGpxCD6uEdzkBZM7sQz3cA?e=ZUXRHk

    Thank you :)

  • User Avatar
    0
    Neozzz created

    hi, i hope you were able to get the file from the link.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Sorry, but I want say, please share the API Host application logs, the logs you provided is not useful.

  • User Avatar
    0
    Neozzz created

    Sorry, but I want say, please share the API Host application logs, the logs you provided is not useful.

    Hi, the file i shared is from the logs folder inside http api host project folder. could you please let me know where is the file that youre looking for? thank you

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Maybe I can check it remotely. shiwei.liang@volosoft.com

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ABP uses a naming convention to register DI.

    Your repository name is CompanyBRRepository and it should be CompanyBranchRepository

    Also, see: https://docs.abp.io/en/abp/latest/Dependency-Injection

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38