Sequence包含多个元素MVC [英] Sequence contains more than one element MVC

查看:79
本文介绍了Sequence包含多个元素MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么可能是错的。它正常工作,直到我添加新属性'国家'然后添加迁移。以及如何在屏幕中为所有团队对象添加国家/地区并创建新团队。重建。更新数据库,我得到错误

 public static List< Team> GetTeams()
{
List< Team> teams = new List< Team>()
{
new Team()
{
TeamName =Canucks,
City =Vancouver,
省=BC,
国家=加拿大
},
新团队()
{
TeamName =Oilers,
City =埃德蒙顿,
省=艾伯塔省,
国家=加拿大
},
新队伍()
{
TeamName = Flames,
City =Calgary,
Province =Alberta,
Country =Canada
},
new Team()
{
TeamName =Sharks,
City =San Jose,
省=加利福尼亚,
国家=美国
}
};
返回队伍;
}



这个新房产的地方如下:

公共课团队
{
[Key]
[MaxLength(10)]
public string TeamName {get;组; } //主键
public string City {get;组; }
public string Province {get;组; }
public string Country {get;组; }

public List< Player>玩家{得到;组; } //团队与玩家/团队的关系可以有多个玩家
}





我尝试过:



我在互联网上发现的一切都依赖于FirstOrDefault。但我不使用这个

解决方案

你使用EF吗?如果是,则从数据库更新模型并查看结果。


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

解决方案

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


这篇关于Sequence包含多个元素MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆