Global() публичный статический Метод

public static Global ( ) : IDisposable
Результат IDisposable
Пример #1
0
        public static ResetLazy <T> WithoutInvalidations <T>(Func <T> func, LazyThreadSafetyMode mode = LazyThreadSafetyMode.ExecutionAndPublication) where T : class
        {
            ResetLazy <T> result = new ResetLazy <T>(() =>
            {
                using (ExecutionMode.Global())
                    using (HeavyProfiler.Log("ResetLazy", () => typeof(T).TypeName()))
                        using (Transaction tr = Transaction.InTestTransaction ? null : Transaction.ForceNew())
                            using (new EntityCache(EntityCacheType.ForceNewSealed))
                            {
                                var value = func();

                                if (tr != null)
                                {
                                    tr.Commit();
                                }

                                return(value);
                            }
            }, mode,
                                                     declaringType: func.Method.DeclaringType);

            registeredLazyList.Add(result);

            return(result);
        }
Пример #2
0
        static Expression <Func <T, bool> > GetFilterAutomatic <T>(Table table) where T : Entity
        {
            if (table.PrimaryKey.Identity)
            {
                var max = ExecutionMode.Global().Using(_ => Database.Query <T>().Max(a => (PrimaryKey?)a.Id));
                if (max == null)
                {
                    return(a => true);
                }

                return(a => a.Id > max);
            }

            var count = ExecutionMode.Global().Using(_ => Database.Query <T>().Count());

            if (count == 0)
            {
                return(a => true);
            }

            throw new InvalidOperationException($"Impossible to determine the filter for the IDs query automatically because the table is not Identity and has rows");
        }