0

I have a list that I created from a SQL query and another list using linq:

var List1 = db.Database.SqlQuery<Apples>("spAllApples AppleNum", param).ToList();
var List2 = (from r in db.bananas where r.bananaNum == id).ToList();

The problem I have ran into is that one shows up as a list and the other as an IEnumerable when I try to combine them using .Concat() as well as AddRange as mentioned here.

I have also tried doing this:

IEnumerable<Apples> List3 = List1.ToList();
List3.Concat(List2);

and was met with the error

IEnumerable<Apple> does not contain a definition for 'Concat' or 'AddRange'

Due to permissions, I do not have access to write stored procs for List2 which would have been the other simple fix. How do I go about combining these two lists?

sgmoore
  • 15,694
  • 5
  • 43
  • 67
Skullomania
  • 2,225
  • 2
  • 29
  • 65
  • 1
    Are you missing `using System.Linq;` ? Also , the first part of your message is confusing because the code is invalid and because you don't actually say what happens when you try to combine them using .Concat() . – sgmoore Sep 19 '20 at 21:55
  • `List1` is already a `List`. And as `List` implements the `IEnumerable` interface, you can just use the `Concat` extension method on `IEnumerable` and do `var List3 = List1.Concat(List2).ToList()`. But this still won't work, because you can't add bananas to a list of apples. Same as you asked in this question a few hours ago https://stackoverflow.com/questions/63970288/how-do-i-merge-two-seperate-tolist – derpirscher Sep 19 '20 at 22:11

0 Answers0