//TODO: I think these Repository methods should be static public virtual int CountOfElements() { try { var count = (from u in SessionProxy.Query <T>() select u).Count(); return(count); } catch (Exception ex) { DiscardCurrentSession(); string errorMessage = BuildErrorMessage(ex); AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace); return(-1); } }
//TODO: I think these Repository methods should be static public virtual IQueryable <T> FindAll(bool returnsIQueryable) { try { var query = from u in SessionProxy.Query <T>() select u; return(query); } catch (Exception ex) { DiscardCurrentSession(); string errorMessage = BuildErrorMessage(ex); AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace); return(null); } }
public virtual bool Delete(T theEntity) { using (var transaction = sessionProxy.BeginTransaction()) { try { sessionProxy.Delete(theEntity); transaction.Commit(); return(true); } catch (Exception ex) { transaction.Rollback(); DiscardCurrentSession(); string errorMessage = BuildErrorMessage(ex); AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace); return(false); } } }
protected virtual void DiscardCurrentSession() { if (sessionProxy != null) { //Try flushing the session try { sessionProxy.Flush(); } catch (Exception ex) { string errorMessage = BuildErrorMessage(ex); AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace); } finally { sessionProxy.Close(); sessionProxy = null; } } }
//TODO: I think these Repository methods should be static public virtual IList <T> FindAll() { try { //OMM: I use this dirty hack to generate DDL statement then comment out the two lines of code //Risky Affair: If you forget to comment them out you will overwrite the database. //ISession session = DigitizingDataDomain.Helpers.NHibernateHelper.OpenSessionForDdl(); //session = null; var query = from u in SessionProxy.Query <T>() select u; return(query.ToList()); } catch (Exception ex) { DiscardCurrentSession(); string errorMessage = BuildErrorMessage(ex); AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace); return(new List <T>()); } }