Merge 2 complex lists into c #

I am programming in silverlight (c# .net)

lets say I have a list of type “data”

public class data
{
    public string QUOTE_ID { get; set; }
    public string EVENT_ACTION_CD { get; set; }
    public string CUSTOMER_NAME { get; set; }
    public string ADAPTIV_CODE { get; set; }
}

the problem is some of the data comes from 1 database and the other data comes from another, so right now i get the data in 2 steps – so i have something like this (using random numbers):

input1 = new List //data return from database 1
//(the data is actually returned as a datable which i convert to a list
//to put to a datagrid, but the end result is shown below)
{
    new data { QUOTE_ID = "1", EVENT_ACTION_CD = "2"},
    new Project { QUOTE_ID = "2", EVENT_ACTION_CD = "4"},
    new Project { QUOTE_ID = "3", EVENT_ACTION_CD = "5"}
};

input2 = new List //data return from database 2
{
    new data { QUOTE_ID = "1", CUSTOMER_NAME = "2", ADAPTIV_CODE ="5"},
    new Project { QUOTE_ID = "2", CUSTOMER_NAME = "4", ADAPTIV_CODE = "5"},
    new Project { QUOTE_ID = "3", CUSTOMER_NAME = "5", ADAPTIV_CODE = "7"}
};

so i should have 2 lists like input1:

(1, 2, null, null
2, 4, null, null
3, 5, null, null)

and input2:

(1, null, 2, 5
2, null, 4, 5
3. null, 5, 7)

how do i join them together to form one input list to become

(1, 2, 2, 5
2, 4, 4, 5
3, 5, 5, 7)

Use linq with a join operator.

See http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

var resultList = (from item in input1
                 join item2 in input2 on item2.QUOTE_ID equals input2.QUOTE_ID
                 let item.CUSTOMER_NAME = item2.CUSTOMER_NAME
                 let item.ADAPTIV_CODE = item2.ADAPTIV_CODE
                 select item).ToList();
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Merge 2 complex lists into c #

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录