Ravi Ram
Ravi Ram

Reputation: 24488

Lambda Select passing extra parameter

I have a Category table where I pass the results into a method :

view.Category = ctx.Categories.Select(CategoryMap.IndustryPage).ToList();

which works perfect. Now I want to pass in an extra item to the IndustryPage() function

public static CategoryIndustryView IndustryPage(DAL.Category data, int indID)

I tired the following but I know the syntax is way off:

view.Category = ctx.Categories.Select(CategoryMap.IndustryPage(this,industryID)).ToList();

How can I pass the indID into the Select so it is accessible in the IndustryPage() function?

UPDATE / WORKING

Using @MarcinJuraszek below I was able to get it working with:

var catData = ctx.Categories.ToList();
view.Category = catData.Select(x => CategoryMap.IndustryPage(x, industryID)).ToList();

I first retrieved the records into catData then did the SELECT .. worked!

Upvotes: 1

Views: 934

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

Use lambda expression instead of method group:

view.Category = ctx.Categories.Select(x => CategoryMap.IndustryPage(x, industryID)).ToList();

Upvotes: 5

Related Questions