Is there a performance difference between the two, for example, I have these two code snippets:
public void Insert(IEnumerable<ManageGeofenceViewModel> geofences) { var insertGeofences = new List<Geofence>(); foreach(var geofence in geofences) { Geofence insertGeofence = new Geofence { name = geofence.Name, radius = geofence.Meters, latitude = geofence.Latitude, longitude = geofence.Longitude, custom_point_type_id = geofence.CategoryID }; insertGeofences.Add(insertGeofence); } this.context.Geofences.InsertAllOnSubmit(insertGeofences); this.context.SubmitChanges(); }
vs
public void Insert(IEnumerable<ManageGeofenceViewModel> geofences) { foreach(var geofence in geofences) { Geofence insertGeofence = new Geofence { name = geofence.Name, radius = geofence.Meters, latitude = geofence.Latitude, longitude = geofence.Longitude, custom_point_type_id = geofence.CategoryID }; this.context.Geofences.InsertOnSubmit(insertGeofence); } this.context.SubmitChanges(); }
Which of the two options is better, and the two code snippets have the same number of trips to the database, since in the first snippet snippet is called outside the loop?
source share