asp.net - Which is better to use for adding IEnumerable object? -
i have found 2 ways implement add operation on ienumerable objects in repository pattern.
first use .addrange()
& pass list in here. or second convert list array & use .addorupdate(arrayobject)
.
which better use if intension remove foreach loop on ienumerable items? please help.
_context.dbset<myentity>().addorupdate(entities.toarray());
or
_context.dbset<myentity>().tolist().addrange(entities);
addorupdate can called array of new objects, can create array of type city[] , call context.cityset.addorupdate(cc => cc.id, cityarray); once. in generated sql, there should condition.
in case of performance, read following
https://stackoverflow.com/a/21839455/194345
and following:
context.bulkinsert(hugeamountofentities);