There is a List<Change>

  public class Change { public string TableName { get; set; } public ChangeType ChangeType { get; set; } public string PrimaryKey { get; set; } public string ColumnName { get; set; } public string OldValue { get; set; } public string NewValue { get; set; } } 

and there is an entity that has the same properties, but also several of its own.

Can I add all the elements from the list to the entity without a loop, or does it still require a loop on the list?

  • What's the problem with the loop? - VladD

1 answer 1

If I understand you correctly, then so.
Suppose you have a ChangeEntity entity. To do without a loop, we can use the AddRange function, using the Select method first, to convert Change objects into a сhangeEntity entity сhangeEntity

 сhangeEntityObjects.AddRange(changes.Select(c => new ChangeEntity() { TableName = c.TableName .... });