0

I have the following;

var res = d.Select(r => new MPageModel
{
    Url = r[0],
    PageTitle = r[1],
    Value = r[2]                  
});

It works. But I need to lookup Url and PageTitle in a database, based on the value from r[0]. So something like;

var res = d.Select(r => new MPageModel
{
    var dbitem = GetDbItem(r[0]);
    Url = dbitem.Url,
    PageTitle = dbitem.Title,
    Value = r[2]                            
});

Obviously this is not at all valid, but I hope it illustrates, what i am trying to do. What is the correct apporach?

brother
  • 7,651
  • 9
  • 34
  • 58
  • `....Select(r => { var s1 = call(r); return new { S1 = s1.s1 };})` should work – Selvin Jul 30 '19 at 13:28
  • 1
    What **is** `d`? Or more precise? What elements does it contain? It seems to be some list of lists. – MakePeaceGreatAgain Jul 30 '19 at 13:33
  • @HimBromBeere sorry, d is an IList – brother Jul 30 '19 at 13:35
  • If the duplicate doesn't help, let me know. Where did `d` **come from**? A database? Somewhere else? – mjwills Jul 30 '19 at 13:38
  • "Statement lambda" works and is efficient, but if you like to make it more convoluted there's also this: `d.Select(r => new { DbItem = GetDbItem(r[0]), Value = r[2] }).Select(x => new MPageModel { Url = x.DbItem.Url, PageTitle = x.DbItem.Title, Value = x.Value})`. – Dialecticus Jul 30 '19 at 13:41

0 Answers0