【发布时间】:2021-11-17 00:22:00
【问题描述】:
accountAging 并且我正在尝试将属于 accountNotes 数据库表中的 accountId 的注释添加到 accountsAging 列表的 AccountNotes 字段中。我首先尝试了这种方法:
foreach (var account in accountAging)
{
account.AccountsReceivableNotes = accountNotesList.Where(n => n.AccountId == account.AccountId).Select(n => n.Content).FirstOrDefault();
}
但出于性能原因,我想避免循环,因为我有很多数据。
一篇文章建议进行连接以获得更好的性能。所以我在下面尝试了这个。但是,我想知道是否有一种简单的方法可以分配 accountAging 中的所有字段而不指定每个字段。有超过 15 个以上的字段。下面的这种方法会清除 AccountAging 中其他字段中的所有值,只给我 AccountNotes。循环当然有效,但试图优化代码。谢谢。
var c = from a in accountAging
join n in accountNotesRepository.All.AsEnumerable()
on a.AccountId equals n.AccountId
select new AccountAging
{
AccountNotes = n.Content
};
【问题讨论】:
标签: c# performance linq