没有错误发生。 Visual Studio .NET Core 2.2 Razor Pages会生成并运行,但只会返回第一次Linq等待中的数据。我实质上是在尝试通过使用Concat方法来做一个UNION。我尝试了Concat并将其替换为.Union,但是没有运气,只是第一个查询返回到Razor Page。剃刀页面被命名为“ BoardMembers”。
public IList<OESAC.Models.BoardMembers> BoardMembers { get; set; }
public IList<OESAC.Models.BoardMembers> BoardMembers2 { get; set; }
public async Task OnGetAsync()
{
// BoardMembers = await _context.BoardMembers.Where(x=> (x.Office !=null) && (x.WebDisplaySection =="Officers")).ToListAsync();
BoardMembers = await _context.BoardMembers
.Select(p => new OESAC.Models.BoardMembers
{
Office = p.Office,
WebDisplaySection = p.WebDisplaySection,
Representing = p.Representing,
WholeName = p.WholeName
}).Where(p=>p.WebDisplaySection == "Officers").ToListAsync();
BoardMembers2 = await _context.BoardMembers
.Select(p => new OESAC.Models.BoardMembers
{
Office=p.Office,
WebDisplaySection=p.WebDisplaySection,
Representing= p.Representing,
WholeName=p.WholeName
}).Where(p=> p.WebDisplaySection == "Board of Directors").ToListAsync();
BoardMembers.Concat(BoardMembers2).ToList();
}
我用“ .ToList();”尝试了最后一行毫无结果。
答案 0 :(得分:1)
如果您使用的是Concat,则需要创建一个新列表来保存返回的串联列表。
Var BoardMembers3 = BoardMembers.Concat(BoardMembers2).ToList();
但是,您可以使用AddRange将Boardmembers2列表合并为Boardmembers。
BoardMembers.AddRange(BoardMembers2);