I am trying insert into database my model with relation one to many:
I have two models:
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public virtual Country Country { get; set; }
}
public class Country
{
public int Id { get; set; }
public string CountryName { get; set; }
public virtual ICollection<User> Users { get; set; }
}
User user = new User()
{
Name = model.Name,
Surname = model.Surname,
Country = new Country { Id = 1 }
};
When I try to insert it to the database I get exception
Validation failed for one or more entities.
The CountryName field is required (CoutryName column is required in database)
I don't want each time call to database to get full Country object, any ideas?