subsonic / SubSonic-3.0-Templates

T4 Template Project for the peeps
http://subsonic.github.io/
105 stars 46 forks source link

ActiveRecord SingleOrDefault triggers two database queries #15

Open georgexcollins opened 15 years ago

georgexcollins commented 15 years ago

SingleOrDefault method: results.Count() triggers a Count(*) query, then single=results.ToList()[0]; triggers a SELECT.

This can be avoided by calling "ToList()" first, then checking if the List is empty. I have committed a patch but not sure if the Pull Request went through...

Also, the overload of SingleOrDefault with additional Provider details isn't calling OnLoaded, SetIsLoaded and SetIsNew.

Cheers, GC