LINQ In Line Property Update During Join

后端 未结 6 1427
难免孤独
难免孤独 2021-02-05 11:55

I have two obects, A & B for this discussion. I can join these objects (tables) via a common relationship or foreign key. I am using linq to do this join and I only want t

6条回答
  •  情深已故
    2021-02-05 12:23

    you can try by following..

                var list1 = new List
                            {
                                new ItemOne {IDItem = 1, OneProperty = "1"},
                                new ItemOne {IDItem = 2, OneProperty = null},
                                new ItemOne {IDItem = 3, OneProperty = "3"},
                                new ItemOne {IDItem = 4, OneProperty = "4"}
                            };
            var list2 = new List
                            {
                                new ItemTwo {IDItem = 2, TwoProperty = "2"},
                                new ItemTwo {IDItem = 3, TwoProperty = "3"},
                            };
    
    
            var query = list1.Join(list2, l1 => l1.IDItem, l2 => l2.IDItem, (l1, l2) =>
            {
                l1.OneProperty = l2.TwoProperty;
                return l1;
            });
    

提交回复
热议问题