/// <summary> /// Gets the specified entity from the information store. /// The first call to this function caches the result in the HTTP context (if available); /// subsequent calls during the same HTTP context will retrieve the item from the context /// instead of the database. /// </summary> public static FileList_Module Get( int moduleId ) { FileList_Module item = null; string cacheKey = GetCacheKey( moduleId ); HttpContext context = HttpContext.Current; if (null != context) //may be null in a non-web environment (e.g., unit tests). { //try the cache of the current HTTP request. item = context.Items[cacheKey] as FileList_Module; } if (null == item) { item = Find( moduleId, null, null).First; if (null != context) { //cache the item. context.Items[cacheKey] = item; } } return(item); }
/// <summary>Saves the entity to the information store.</summary> private static int Save_(FileList_Module entity) { int retval = 0; entity.OnPreSave(); using (SqlCommand cmd = entity.GetSaveCommand(true)) { using (cmd.Connection) { cmd.Connection.Open(); cmd.ExecuteNonQuery(); } entity._isNew = false; //Note: it is _not_ necessary to call RemoveFromContextCache() //during Save, because the object being saved is the same object //referenced by the context cache--hence, it is up-to-date. retval = (int)cmd.Parameters["@RETVAL"].Value; } entity.OnPostSave(); return(retval); }
public static FileList_ModuleCollection GetTypedList(SqlDataReader r) { FileList_ModuleCollection items = new FileList_ModuleCollection(); FileList_Module item = null; while (r.Read()) { item = new FileList_Module(); item.ModuleId = r.GetInt32(r.GetOrdinal("ModuleId")); item.RootPath = r[r.GetOrdinal("RootPath")] as string; item.ShowFolderList = r.GetBoolean(r.GetOrdinal("ShowFolderList")); item._isNew = false; items.Add(item); } return(items); }