【发布时间】:2015-12-05 16:51:26
【问题描述】:
我需要能够从 ASP.NET DropDownList 中搜索单个名称,然后将具有该名称的 player 添加到列表中。
我的查询如下所示:
List<Player> players = new List<Player>();
var p1 = from p in db.Players
where p.PlayerName == DropDownListPlayer1.SelectedItem.Text
select p;
然后,我不知何故需要将此结果添加到列表中,但是
players.Add(p1);
给了我两个错误:
无法从“System.Linq.IQueryable”转换为“播放器”,
还有:
最好的重载方法匹配 'System.Collections.Generic.List.Add(Player)' 有一些无效 论据。
我尝试让查询选择一个新的 Player 实例:
var p1 = from p in db.Players
where p.PlayerName == DropDownListPlayer1.SelectedItem.Text
select new Player {PlayerName = p.PlayerName,
PlayerId = p.PlayerId};
除了将结果发送到列表中,并将列表中的第一个(也是唯一一个)玩家添加到新列表中,这一切都无济于事。
【问题讨论】:
-
这是 windows 还是 web 先生?