Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what can be wrong. it works properly untill I add new property 'Country' then add-migration. and how in screen I add for all team objects a country and create new team. rebuild. update-database and i get mistake
public static List<Team> GetTeams()
     {
         List<Team> teams = new List<Team>()
         {
             new Team()
             {
                 TeamName = "Canucks",
                 City = "Vancouver",
                 Province = "BC",
                 Country = "Canada"
             },
             new Team()
             {
                 TeamName = "Oilers",
                 City = "Edmonton",
                 Province = "Alberta",
                 Country = "Canada"
             },
             new Team()
             {
                 TeamName = "Flames",
                 City = "Calgary",
                 Province = "Alberta",
                 Country = "Canada"
             },
             new Team()
             {
                 TeamName = "Sharks",
                 City = "San Jose",
                 Province = "California",
                 Country = "USA"
             }
         };
         return teams;
     }

the place with new property loocks like this:
public class Team
    {
        [Key]
        [MaxLength(10)]
        public string TeamName { get; set; } //primary key
        public string City { get; set; }
        public string Province { get; set; }
        public string Country { get; set; }

        public List<Player> Players { get; set; }//team has relationship with player/ team can have multuply players
    }


What I have tried:

All i found on the internet depence on FirstOrDefault. But I don't use this
Posted
Updated 28-Aug-18 5:20am
Comments
Er. Puneet Goel 28-Aug-18 2:10am    
Are you using code first approach?
Member 13950417 30-Aug-18 10:47am    
yes.
Richard Deeming 28-Aug-18 12:23pm    
Show the code that throws the exception.
Member 13950417 30-Aug-18 10:55am    
the whole code you can get by reference https://drive.google.com/open?id=1sp8YwdO3I1MEoYkIO0JeC8q70OcvbSjf it's just example and I'm sure there lots of mistake. I'm beginner
Richard Deeming 30-Aug-18 11:01am    
No, I'm not downloading a random file from a stranger on the internet just to debug your code.

Click the green "Improve question" link, and add a code block with the code that throws the exception. Remember to indicate which line of code the exception is thrown from.

1 solution

Are you using EF? If yes then update the model from database as well and see the result.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900