I have two entities
public class Tax
{
public int Id { get; set; }
public string Name { get; set; }
public int ClientId { get; set; }
public Client Client { get; set; }
}
public class Client
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Tax> Taxes { get; set; }
}
and in this method, I want to create a relationship between Client and Tax using ClientId, but i am getting The Client field is required error on client side, so I want to ignore field Client.
My question is how to ignore fielf client or if I'm doing something wrong, then how to create one-to-many relationship in Post method? (I'm new to ASP.NET so sorry if this is a stupid question.)
[HttpPost]
public IActionResult Post(Tax tax)
{
tax.Client = (from c in context.Clients
where c.Id == tax.ClientId
select c).FirstOrDefault<Client>();
context.Taxes.Add(tax);
context.SaveChanges();
return Created("api/taxes", tax);
}