SqlException: Invalid column name ‘CountryMasterCountryId’

Issue

This Content is from Stack Overflow. Question asked by siddhesh

I am doing CRUD operation using asp .net core 6 MVC (visual studio 2022). For this i complete County Create,Update,Delete,Read operation. but now i am trying cascading dropdown in state with relation county db. when i write “public virtual CountryMaster CountryMaster” and “public virtual ICollection StateMasters” in the models on state and country it give me error of sqlException:Invalid column name ‘CountryMasterCountryId’. here is Country model
”’

{
    [Key]
    public int CountryId { get; set; }

    [Display(Name = "Country Name")]
    [Required(ErrorMessage ="Please Enter Country")]
    public string CountryName { get; set; } = null!;

    [Display(Name ="When Entered")]
    public DateTime WhenEntered { get; set; } = DateTime.UtcNow;

    [Display(Name ="When Modified")]
    public DateTime WhenModified { get; set; }= DateTime.UtcNow;

    public virtual ICollection<StateMaster> StateMasters { get; set; }
} '''

here is State model
”’

{
    [Key]
    public int StateId { get; set; }

    [Required(ErrorMessage ="Please Enter State Name")]
    public string StateName { get; set; } = null!;

    
    [Display(Name = "Country Name")]
    public int CountryId { get; set; }

    [Display(Name = "When Entered")]
    public DateTime WhenEntered { get; set; } = DateTime.UtcNow;

    [Display(Name = "When Modified")]
    public DateTime WhenModified { get; set; } = DateTime.UtcNow;

    public virtual CountryMaster CountryMaster { get; set; } 
}

”’
What i do? Is Icollection different in .net core 6 MVC?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?