Hi Aall,
I am completely new to Entity framework, working on sample app.
Following the .entity framework CodeFirst approach for asp.net core web api
we created two entities
public class Account
{
public int AccountId { get; set; }
public int AccountNumber { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public decimal Balance { get; set; }
public int AccountTypeId { get; set; }
public AccountType AccountType { get; set; }
}public class AccountType
{
public int AccountTypeId { get; set; }
public string Type { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public List<Account> Accounts { get; set; }
}These are the two entities to for simulating a bank account
We have created a APi endpint for Creating account like below
[HttpPost]
public async Task<ActionResult<Account>> CreateAccount(Account account)
{
return await _accountService.AddAccountAsync(account);
}But the problem is the swagger is showing the parameter like below
{"accountId": 0,"accountNumber": 0,"createdDate": "2021-04-19T04:08:22.058Z","modifiedDate": "2021-04-19T04:08:22.058Z","balance": 0,"accountTypeId": 0,"accountType": {"accountTypeId": 0,"type": "string","name": "string","description": "string","createdDate": "2021-04-19T04:08:22.058Z","modifiedDate": "2021-04-19T04:08:22.058Z","accounts": ["string"
]
}
}how do I pass only the account details for creation ? because it has both account and accountype fields are present
am doing anything wrong while defining the relationship between entities.
My intention is to reference the AccountTypeId mentioned in the account so that it wont insert accountypeid other than in the accountype table
please correct me if I am doing anything wrong
thanks