简体   繁体   中英

Is this possible with LINQ-to-Entities query using Lambda Expression

Looking for direction and understanding of the approach to implement logic to handle the scenario below, if possible with LINQ-to-Entities. New to LINQ and Entity Framework, but understand the basics. Intermediate with C#.

I have a function, which needs to iterate through and add information to a results set and ultimately pass back the "processed" result set. I'd like to be able call this function in an inline/Lambda/method based way with the LINQ query that retrieves the data. So something like this:


    IQueryable<Rates> = db.Rates.Select(r => r).ProcessRates();

So what LINQ/C# construct am I going to employ to implement the function? Would it be an extension method or ???

Answers with explanation and code snippets will be greatly appreciated, especially the syntax necessary to create the function properly.

Yes this would require an extension method on IEnumerable<Rates> .

Something like this ought to work:

public static IQueryable<Rates> ProcessRates(this IEnumerable<Rates> rates)
{
    foreach (Rates r in rates)
        r.Process();

    return rates.AsQueryable();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM