Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
var datasource = new NORTHWNDEntities().Categories.ToList();
       var datasource1 = new NORTHWNDEntities().Customers.ToList();
       var datasource2 = new NORTHWNDEntities().Orders.ToList();
Posted
Comments
Sergey Alexandrovich Kryukov 13-Jun-14 2:25am    
What does "concat" mean? What have you tried so far?
—SA
Debabrata_Das 13-Jun-14 3:05am    
Did you mean merging three lists into a single object?
ilaya muthumanickam 13-Jun-14 3:35am    
yes absolutely /var Datasource = datasource.Concat(datasource1)Concat(datasource2);
i tried this one But it's not apt....
Debabrata_Das 13-Jun-14 3:53am    
If you want to merge the above three data source into a single List (in a single column) then solution provided by Manikanandan10 will solve your problem.
ilaya muthumanickam 13-Jun-14 4:39am    
yes please help me

See the following code:

C#
class Program
{
    static void Main(string[] args)
    {
        List<int> a = new List<int>();
        a.Add(1);
        a.Add(2);

        List<int> b = new List<int>();
        b.Add(3);
        b.Add(4);

        List<int> c = new List<int>();
        c.Add(5);
        c.Add(6);

        List<int> concat = new List<int>(a.Concat(b).Concat(c));

        for (int i = 0; i < concat.Count; ++i)
        {
            Console.WriteLine(concat[i]);
        }
        Console.ReadKey();
    }
}
 
Share this answer
 
Comments
ilaya muthumanickam 13-Jun-14 4:52am    
Thanks for your reply Manikandan. But i need to concatenate three Ienumarable

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
[no name] 13-Jun-14 8:53am    
Where exactly are you getting this error? If datasource, datasource1, datasource2 are IEnumerable, then the line
var Datasource = datasource.Concat(datasource1).Concat(datasource2);
should not produce any error. See Solution 2.
In your code,
C#
var datasource = new NORTHWNDEntities().Categories.ToList();
var datasource1 = new NORTHWNDEntities().Customers.ToList();
var datasource2 = new NORTHWNDEntities().Orders.ToList();

If these three lines are correct and datasource, datasource1 and datasource2 are IEnumerable then your code shouldn't produce any error. Are you getting the error in this line?
C#
ViewData["datasource"] = Datasource;

Does new NORTHWNDEntities().Categories.ToList(); returns a IEnumerable, then your code shouldn't produce errors.

And to concat three IEnumberables, the following code works(a modification of code in Soln 1):
C#
List<int> a = new List<int>();
a.Add(1);
a.Add(2);

List<int> b = new List<int>();
b.Add(3);
b.Add(4);

List<int> c = new List<int>();
c.Add(5);
c.Add(6);

IEnumerable<int> a2 = a.Cast<int>();
IEnumerable<int> b2 = b.Cast<int>();
IEnumerable<int> c2 = c.Cast<int>();

IEnumerable<int> concat = a2.Concat(b2).Concat(c2);

And also, don't use var always. I'm not against var, but you should know the type of the object before you use it.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900