0

I have a relational database that I prepared with the DbFirst approach. While posting entity class for post model it goes in property of other class type inside entity class. Below are the properties of my entity class.

public class CurrencyAccount : BaseEntity
    {
        [ForeignKey("CompanyId")]
        public int CompanyId { get; set; } // Company Class
        public string Code { get; set; } // Use for transfer data to other software
        public string Name { get; set; }
        public string Adress { get; set; }
        public string? TaxOffice { get; set; } // Nullable
        [MaxLength(10)]
        public string? TaxIdNumber { get; set; } // Nullable char(10)
        [MaxLength(11)]
        public string? IdentityNumber { get; set; } // Nullable char(11)
        public string? Email { get; set; } // Nullable
        public string? Authorizedperson { get; set; } // Nullable

// Navigation Property
public Company? Company { get; private set; }
public List<BaBsReconciliation>? BaBsReconciliations { get; private set; }
public List<AccountReconciliation>? AccountReconciliations { get; private set; }

Below are the codes of the Add method in my API control

 [HttpPost("add")]
        public IActionResult Add(CurrencyAccount currencyAccount)
        {

            var result = _currencyAccountService.Add(currencyAccount);
            if (result.IsSuccess)
            {
                return Ok(result);
            }
            return BadRequest(result.Message);
        }

Below is the screenshot of Swagger Swagger Screenshot

Briefly, as you can see in the screenshot, I don't want the Company class inside the CurrencyAccount class in the post operation. Thank you so much

  • 1
    Create a separate model, something like in this article [Create Data Transfer Objects (DTOs)](https://learn.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5) – T. Dominik Oct 17 '22 at 12:31

1 Answers1

0

As far as I can understand, you should use DTO's . You can specify which you want to see.

What is a Data Transfer Object (DTO)?

  • I'm currently using dto and mapping later. I was wondering if there could be a shorter way. Thank you for the answer – hasanUtebay Oct 18 '22 at 10:32