我有一个用DbFirst方法准备的关系数据库。当为post模型发布实体类时,它会进入实体类中其他类类型的属性中。下面是我的实体类的属性。
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; }
下面是我的API控件中Add方法的代码
[HttpPost("add")]
public IActionResult Add(CurrencyAccount currencyAccount)
{
var result = _currencyAccountService.Add(currencyAccount);
if (result.IsSuccess)
{
return Ok(result);
}
return BadRequest(result.Message);
}
下面是Swagger
的屏幕截图
简单地说,正如您在屏幕截图中所看到的,我不希望在post操作中将Company类放在CurrencyAccount类中。
1条答案
按热度按时间doinxwow1#
据我所知,你应该使用DTO。你可以指定你想看到的。
What is a Data Transfer Object (DTO)?