locked
How can i Concat multiple IEnumarable to single? RRS feed

  • Question

  • User2057092666 posted

    public ActionResult Index()
    {

    var datasource = new NORTHWNDEntities().Categories.ToList();
    var datasource1 = new NORTHWNDEntities().Customers.ToList();
    var datasource2 = new NORTHWNDEntities().Orders.ToList();

    var Datasource = datasource.Concat(datasource1).Concat(datasource2);


    ViewData["datasource"] = Datasource;


    return View();
    }

    Error 'System.Collections.Generic.List<SyncFusionExample.Models.Employee>' does not contain a definition for 'Union' and the best extension method overload 'System.Linq.Queryable.Union<TSource>(System.Linq.IQueryable<TSource>, System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments C:\Users\Administrator\Desktop\setup .net 3.5\EJ sample\SyncFusionExample\SyncFusionExample\Controllers\HomeController.cs 62 30 SyncFusionExample

    Friday, June 13, 2014 3:23 AM

Answers

  • User-1805286477 posted
    // Try this one
    public void Answer()
    {
        IEnumerable<YourClass> first = this.GetFirstIEnumerableList();
        //Assign to empty list so we can use later
        IEnumerable<YourClass> second = new List<YourClass>();
    
        if (IwantToUseSecondList)
        {
            second = this.GetSecondIEnumerableList();
        }
        IEnumerable<SchemapassgruppData> concatedList = first.Concat(second);
    }

    </div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 13, 2014 5:18 AM

All replies

  • User1401801381 posted

    you try to concatenate list of different objects, it will not work

    I assume you want to retrieve a list of orders that belong to customers being in a category, if so you can use a linq query: 

    something that looks like this

    var query = from cat in categories
    from cust in cat.Customers
    from order in cust.Orders
    select new {
    cat.name,
    cust.name,
    order.description
    }

    Friday, June 13, 2014 4:13 AM
  • User2057092666 posted

    Thanks for your kind reply this one is not suitable for my requirement,

    I need to concatenate above three IEnumarable......

    Friday, June 13, 2014 4:30 AM
  • User-1805286477 posted
    // Try this one
    public void Answer()
    {
        IEnumerable<YourClass> first = this.GetFirstIEnumerableList();
        //Assign to empty list so we can use later
        IEnumerable<YourClass> second = new List<YourClass>();
    
        if (IwantToUseSecondList)
        {
            second = this.GetSecondIEnumerableList();
        }
        IEnumerable<SchemapassgruppData> concatedList = first.Concat(second);
    }

    </div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 13, 2014 5:18 AM