-1

I have two linq results as below

-- var itemlist=(from i in context.Items.....................)
-- var otherlist=(from j in context.Extras...................)

both lists contain same 5 columns with ItemID as key.But otherlist has a Quantity column which id blank in Items.I need to club these two lists to one with all details available.Number of rows would be more than 50k in itemlist and lesser in otherlist.Whats the best soln to club these?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Murali Uppangala
  • 884
  • 6
  • 22
  • 49
  • Are the two lists of the same type? If so use `Enumerable.Concat` (http://msdn.microsoft.com/en-us/library/vstudio/bb302894(v=vs.100).aspx). If not make them be of the same type and then use it. – Chris Aug 20 '14 at 09:22
  • `select sameClassName{...}` – Tim.Tang Aug 20 '14 at 09:23
  • Is this context variable a DbContext? Are you trying to join them based on ItemId? How should the columns behave (overwrite one of them, average, sum, whatever...) – ChriPf Aug 20 '14 at 09:41
  • Yes... these two are in a Dbcontext.look below comment for case info on Christos answer. – Murali Uppangala Aug 20 '14 at 09:43
  • Here,the Quantity itook from otherlist(having 30 rows) for itemlist(20k rows) yields 30 rows.I need to get 20k rows with 30 rows edited for quantity. var pricelist = (from i in itemlist join j in otherlist on i.item equals j.item select new { item = i.item, itemDiscription = j.itemDiscription, UM = i.UM, Category = i.Category, Qty = j.Qty, Comments = j.Comments, orderrID = j.orderID, MinQty = i.MinQty, MaxQty = i.MaxQty }); – Murali Uppangala Aug 20 '14 at 10:06

1 Answers1

1

You could use the Concat method:

var result = itemlist.Concat(otherlist);

This method concatenates two sequences. (Beware the type of the two sequences should be the same)

For further documentation about this method, please have a look here.

Christos
  • 53,228
  • 8
  • 76
  • 108
  • the case is like -- both itemlist and otherlist has a column called Quantity.In Itemlist it will be null for all 50k items.In otherlist Quantity>=0.I need to merge this data to itemlist. – Murali Uppangala Aug 20 '14 at 09:38