How do I merge two seperate '.ToList()"?

こ雲淡風輕ζ 提交于 2021-02-11 13:40:59

问题


There are several posts where people are asking how to merge generic lists. However, in my case I have two seperate linq statements where I am returning two separate database results .ToList()

var appleList = (from al in db.Apples where al.Id == id select al).ToList();
var bananaList = (from bl in db.Bananas where bl.Id == id select bl).ToList();

I tried merging these list like so:

appleList.Concat(bananaList);

but this causes the following error:

'List' does not contain a definition for 'Concat'

How do I combine these two .ToList()?


回答1:


Create a fruit class and derive both apples and bananas from it.

https://www.webopedia.com/TERM/B/base_class.html



来源:https://stackoverflow.com/questions/63970288/how-do-i-merge-two-seperate-tolist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!