C# How to pass a Linq ToList()

I am a newbie at LINQ and am having trouble passing a query result into a method

Here is the code:

using (var ctx = new AH_ODS_DBEntities1())
{
    var orlist = ctx.Collections.Where(x => x.AQ_PostStatus == 0).GroupBy(x => x.SourceOR).Select(x => new { Key = x.Key }).ToList();
    foreach(var ordocnumber in orlist) // navigate the list of OR's
    {
        Console.WriteLine(ordocnumber.Key);//+"\n"+fatnotes+"\n");                    
        var orcontents = ctx.Collections.Where(dx => dx.SourceOR == ordocnumber.Key).Select(dx =>
        new
        {
            dx.AmountPaid,
            dx.ApplicationDate,
            dx.Type 
        }).ToList();

        AQEngine2(context, orcontents);   

    }
}

And here is the method that am trying to call. Error says "...method match.... has some invalid arguments"

public static void AQEngine2(KDICOLLECTIONS.Screen context, List<Collection> orcontents)
{
 // some code
}

I don't understand the error and i dont know anymore how to pass the query result properly. I've tried getting rid of ToList() and telling IEnumerable instead of var and also IQueryable and changed the data type of the method accordingly but to no avail.

Please show me the way.

Thanks in advance!

Jon Skeet
people
quotationmark

You're creating a list of instances of an anonymous type with three properties (AmountPaid, ApplicationDate, and Type). Your method expects a List<Collection>. Assuming that Collection is a type with the same properties, you probably just want:

.Select(dx => new Collection
{
    AmountPaid = dx.AmountPaid,
    ApplicationDate dx.ApplicationDate,
    Type = dx.Type 
})

... and leave the rest of the code the same. Then the type of orcontents will be List<Collection> and the call to your method should be fine.

people

See more on this question at Stackoverflow