none
List of Data with LINQ Filter RRS feed

  • Question

  • In the below code TemplateEntityList contains list of templateentity.
    after all coding lstTemplateEntity binds only first template entity data.it is not containg all records.
    please help.

      var TemplateEntityList = objrestlistinfo.RESTInfoResponseList.Select(x => x.TemplateEntityList).Distinct();
    List<Template>     lstTemplateEntity = new List<Template>();
                      
                        foreach (var templatesetset in TemplateEntityList.ToList())
                        {
                            Template obj = new Template();
                            obj.TemplateID = templatesetset[0].TemplateID;
                            obj.TemplateName = templatesetset[0].TemplateName;
                            lstTemplateEntity.Add(obj);
                        }
    • Moved by Caillen Wednesday, November 20, 2013 5:27 AM
    Tuesday, November 19, 2013 6:08 AM

Answers

  • Hello,

    Have a try to change codes to be like below:

    foreach (var templatesetset in TemplateEntityList.ToList())
    
                         {
    
                             lstTemplateEntity =templatesetset;
    
                         }

    Or add a nested foreach like below:

    foreach (var templatesetset in TemplateEntityList.ToList())
    
                         {
    
                            foreach (Template obj in templatesetset)
    
                            {
    
                             lstTemplateEntity.Add(obj);
    
                            }
    
                         }

    If this does not work for you, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 20, 2013 6:53 AM
    Moderator

All replies

  • Hi,

    I'm moving your question to ADO.NET Entity Framework and LINQ to Entities forum for better responses.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 20, 2013 5:28 AM
  • Hello,

    Have a try to change codes to be like below:

    foreach (var templatesetset in TemplateEntityList.ToList())
    
                         {
    
                             lstTemplateEntity =templatesetset;
    
                         }

    Or add a nested foreach like below:

    foreach (var templatesetset in TemplateEntityList.ToList())
    
                         {
    
                            foreach (Template obj in templatesetset)
    
                            {
    
                             lstTemplateEntity.Add(obj);
    
                            }
    
                         }

    If this does not work for you, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 20, 2013 6:53 AM
    Moderator