Looking to do a bit of refactoring… Using NHibernate I have this query currently
public Widget FindByCode(string code)
{
return
_session
.Query<Widget>()
.Where(w => !w.IsDeleted)
.FirstOrDefault(w => w.Code == code);
}
I was thinking of using this
public Widget FindByCode(string code)
{
return
_session
.Query<Widget>()
.Where(w => !w.IsDeleted && w.Code == code)
.FirstOrDefault();
}
Is either one any better than the other? Any tips, links, or code is always appreciated.
Cheers!
In linq2objects or linq2sql you can write just a FirstOrDefault like this:
Not sure about NHibernate, but but probably works. And you can always check the generated sql with NHProf, or regular sql profiler.