/// <summary> /// Requests database persistence for a specific entity in the ambient service scope. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tosave"></param> /// <param name="allRelated">If true, all related entities are also considered as candidates for saving. If false, only the specific entity is considered a candidate for saving.</param> /// <returns></returns> public static T DBSave <T>(this T tosave, bool allRelated) where T : class, new() { var settings = new DBSaveSettings { RootObject = tosave, IncludeRootChildren = allRelated, IncludeRootParents = allRelated, EntityPersistName = GetEntityPersistName <T>(tosave), EntityPersistType = typeof(T) }; CurrentServiceScope.DBSave(settings); return(tosave); }
/// <summary> /// Requests database persistence for a specific entity in the ambient service scope. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tosave"></param> /// <param name="settings"></param> /// <returns></returns> public static T DBSave <T>(this T tosave, DBSaveSettings settings = null) where T : class, new() { if (settings == null) { settings = new DBSaveSettings(); } if (tosave != null && tosave is IEnumerable) { settings.SourceList = ((IEnumerable)tosave).Cast <object>(); } else { settings.RootObject = tosave; } settings.EntityPersistName = settings.EntityPersistName ?? GetEntityPersistName <T>(tosave); settings.EntityPersistType = typeof(T); CurrentServiceScope.DBSave(settings); return(tosave); }
/// <summary> /// Requests database persistence for a specific entity in the ambient service scope. This method unlike DBSave returns a validation-specific code/message that comes from the validation service. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tosave"></param> /// <param name="settings"></param> /// <returns></returns> public static (ValidationErrorCode error, string message) DBSaveWithMessage <T>(this T tosave, DBSaveSettings settings = null) where T : class, new()
/// <summary> /// Requests database persistence over all entities in the ambient service scope. /// </summary> /// <param name="settings"></param> /// <returns>One element per entity saved, indicating any message and/or status returned by the save process for that entity.</returns> public static IEnumerable <(object item, string message, int status)> DBSave(DBSaveSettings settings = null) { return(CurrentServiceScope.DBSave(settings)); }
/// <summary> /// Requests database persistence over all entities in the ambient service scope. /// </summary> /// <param name="settings"></param> /// <returns>One element per entity saved, indicating any message and/or status returned by the save process for that entity.</returns> public static async Task <IEnumerable <(object item, string message, int status)> > DBSaveAsync(DBSaveSettings settings = null) { IEnumerable <(object item, string message, int status)> rv = null; Exception ex = null; await Task.Run(() => { try { rv = CurrentServiceScope.DBSave(settings); } catch (Exception ex2) { ex = ex2; } }); if (ex != null) { throw ex; } return(rv); }
public static async Task <IEnumerable <(object item, string message, int status)> > DBSaveTransactionalAsync(DBSaveSettings settings = null) { IEnumerable <(object item, string message, int status)> rv = null; Exception ex = null; await Task.Run(() => { try { using (var tx = CEF.NewTransactionScope()) { rv = CurrentServiceScope.DBSave(settings); tx.CanCommit(); } } catch (Exception ex2) { ex = ex2; } }); if (ex != null) { throw ex; } return(rv); }