I was doing some profiling to see exactly what Save and SaveAll does in different instances (version 6.3) for a class that has an [AutoIncrement] property.
public class Airport {
[AutoIncrement]
public int Id {get;set;}
public string Name {get;set;}
}
Note for SaveAll I just had one item in a list to test.
My question is why does the Save method do an extra SELECT for a class with an AutoIncrement Id not set (default int = 0) where the SaveAll immediately inserts?
The SaveAll method works perfectly for a class with AutoIncrement in my opinion as this is more efficient. This logic should be applied to Save.
You know the class has an [AutoIncrement] property and if it’s primary key is default (i.e. not set) you can bypass checking if it exists and do an INSERT straight away.
Why does Save need to do that for AutoIncrement Ids though?
If I have an Id int that is set to 0, then you immediately know (by the nature of identity columns) that this can be inserted and can bypass the check to see if it exists.
For non AutoIncrement primary keys, you would indeed need to do the select first to see if it exists.