Beispiel #1
0
 /// <summary>
 /// Получить количество файлов, которое будет после сохранения карточки в БД (мерж карточки с БД)
 /// </summary>
 /// <param name="card">Карточка</param>
 /// <param name="dbScope">Скоуп БД</param>
 /// <returns>Количество файлов после сохранения карточки</returns>
 public static int GetFilesCountInDB(this Card card, IDbScope dbScope)
 {
     using (dbScope.Create())
     {
         var db = dbScope.Db;
         return((int)db.SetCommand(GetNumberOfFilesInDB, new[] { db.Parameter("ID", card.ID) }).ExecuteScalar());
     }
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a transaction scope with the given isolation level.
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="isoLevel"></param>
 public DbTransactionScope(IDbScope scope, IsolationLevel isoLevel)
 {
     _scope = scope;
     this.OwnsTransaction = scope.EnsureTransaction(isoLevel);
 }
Beispiel #3
0
 public UpdateBuilder(IDbScope dbScope)
 {
     this.dbScope = dbScope;
 }
Beispiel #4
0
 public SelectBuilder(IDbScope dbScope)
 {
     this.dbScope = dbScope;
     this.tables.Add(typeof(T));
 }
 /// <summary>
 /// Opens a given database connection if it is not already open, and returns an object, that when disposed, will close the connection only if it was not already open.
 /// </summary>
 /// <param name="scope"></param>
 /// <returns></returns>
 public static DbConnectionScope EnsureOpen(this IDbScope scope)
 {
     return(new DbConnectionScope(scope.Connection));
 }
Beispiel #6
0
        /// <summary>
        /// Получить знание из карточки (если есть) или из БД
        /// </summary>
        /// <param name="card">Карточка</param>
        /// <param name="param">Параметр, значение которого надо получить</param>
        /// <param name="dbScope">Скоуп БД</param>
        /// <typeparam name="T">Тип значения (секция карточки)</typeparam>
        /// <returns>Значение из карточки (если есть) или значение из БД или null</returns>
        public static object GetSectionValueFromCardOrDbOrNull <T>(this Card card, T param, IDbScope dbScope) where T : Enum
        {
            var valueExistOnCard = card.Sections.TryGetValue(typeof(T).Name, out CardSection section) &&
                                   section.RawFields.ContainsKey(param.ToString());

            if (valueExistOnCard)
            {
                return(section.Fields[param.ToString()]);
            }

            using (dbScope.Create())
            {
                var db      = dbScope.Db;
                var command = $"SELECT {param.ToString()} FROM {typeof(T).Name} WHERE ID=@ID";
                return(db.SetCommand(command, new[] { db.Parameter("ID", card.ID) }).ExecuteScalar());
            }
        }