Ali Ylmaz

Ali Ylmaz

  • NA
  • 129
  • 11.7k

Linq To Sql List add Select New

Nov 23 2021 8:37 AM

Hello, when the loop below runs, I need to add elements continuously.

I tried to do something like this but it didn't work. How can I solve this problem.

then i want to pull the data collected in the list.

oreach (var item in products)
{
    List<Urunler> list = new List<Urunler>();
  
    list.Add(from p in models
             select new
             {
                 label = p.Name,
                 producturl = Url.RouteUrl("Product", new { SeName = p.SeName }),
                 productpictureurl = p.DefaultPictureModel.ImageUrl
             };
  
    result = models.Where(x => x.Id == item.Id).Select(p => new
    {
        label = p.Name,
        producturl = Url.RouteUrl("Product", new { SeName = p.SeName }),
        productpictureurl = p.DefaultPictureModel.ImageUrl
  
    }).ToList();
}
  public class Urunler
        {
         
            public string Pname { get; set; }

            public string Url { get; set; }

            public string Photo { get; set; }
        }

 


Answers (2)