问题
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