Fixes for ( DNN-6239 ) AND ( DNN-6218 + DNN-6242 ).

DNN-6239: Upgrade is failing.
DNN-6218 + DNN-6242: DB logging provider throws errors
DNN-6090: fixed thrown error when there are more items in collections (SingleOrDefault replaced with FirstOrDefault).