_listTesta = (from c in _listTesta
join ct in _listTestB
on c.Id equals ct.Id into g
from ct in g.DefaultIfEmpty()
where c.Id != null
select new Testa
{
Name = ct == null ? c.Name : ct.Name,
Family = ct == null ? c.Family : ct.Family,
Id = ct == null ? c.Id : ct.Id,
}).ToArray();
示例数据:
List<Testa> _t = new List<Testa>();
List<TestB> _ta = new List<TestB>();
var _listTesta = Enumerable.Range(1000, 50).Select(i => new Testa(i, "n" +
i, "nf" + i)).ToArray();
var _listTestB = Enumerable.Range(1000, 20).Select(i => new TestB(i, "nb" +
i, "fb" + i)).ToArray();
1条答案
按热度按时间fkvaft9z1#
传递信息的方法有很多。我建议两种方法
1.关于linq
示例数据:
2.用自动机
Automapperautomapper-net-core