0

It is possible to add ListB PurchaseOrderHeader and Supplier into List A PurchaseOrderHeader and Supplier? I had try join, concat, but it see like not working well

POLine.

List A enter image description here

List B enter image description here

Edit

Sorry for forgot to add code

      POLine.Select(c => c.PurchaseOrderHeader).Concat(DataFromParent.Select(c=>c.PurchaseOrderHeader));

Update

It is possible to make it?

List A PurchaseOrderHeader = null, PurchaseOrderLine =some value , Supplier = null

List B only have PurchaseorderLine = null,

can anyhow merge it to make it

List A PurchaseOrderheader = List B PurchaseOrderHeader, List A PurchaseOrderLine remain, and List A Supplier = List B Supplier?

Se0ng11
  • 2,303
  • 2
  • 26
  • 45

4 Answers4

2

It's very hard to understand what exactly you're asking but I think you might just be looking for the following:

// I think this is what you mean with list A and List B
var listA = POLine[0];
var listB = DataFromParent[0];

listA.PurchaseOrderHeader = listB.PurchaseOrderHeader;
listA.Supplier = listB.Supplier;
Rik
  • 28,507
  • 14
  • 48
  • 67
  • 1
    It is unbelievable for you to understand what I actually try to ask, but you actually giving the answer that I want, thanks for the help, and sorry for my bad explanation – Se0ng11 Dec 10 '13 at 09:40
1

You could try:

List<string> a = new List<string>();
List<string> b = new List<string>();

a.AddRange(b);[this question is already asked][1]
Lijo
  • 6,498
  • 5
  • 49
  • 60
  • Sorry, I want to merge, where the null value in List A replace by the value from List B – Se0ng11 Dec 10 '13 at 09:09
  • If you know that the question already has an answer, why repost it verbatim? The correct thing to do is mark the question as a duplicate by flagging/voting to close or leaving a comment in the OP if you lack those privileges. – DGibbs Dec 10 '13 at 09:12
1

Technically, there is no "List A PurchaseOrderHeader": there is a variable "PurchaseOrderHeader", but that variable has no value.

You should first check if it has a value. If it does, you can add the other list to it. If it does not, you might want to assign List B to the variable PurchaseOrderHeader

if (listA == null) listA = listB;
else listA.AddRange(listB);

Judging from your code, it's not clear whether PurchaseOrderHeader is actually a List, so I'm not sure whether .AddRange is actually an option for you.

Rik
  • 28,507
  • 14
  • 48
  • 67
  • anywhere to merge replace the null value from list B? is it possible? – Se0ng11 Dec 10 '13 at 09:10
  • Currently now List A PurchaseOrderHeader = null,PurchaseOrderLine =some value Supplier = null and List B only have PurchaseorderLine = null, can anywhere to merge it to make it List A PurchaseOrderheader = List B PurchaseOrderHeader, List A PurchaseOrder Line remain, and List A Supplier = List B Supplier? – Se0ng11 Dec 10 '13 at 09:12
1

This should solve your problem

List<t> list1=new list1<t>();
List<t> list2=new List<t>();        
list2.AddRange(list1);
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Ramesh
  • 163
  • 1
  • 2
  • 11