Пример #1
0
        protected bool Exists(OneOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var findArgs = new FindOneArgs {
                Query          = options.GetQuery(_getIdValue),
                Fields         = Fields.Include(CommonFieldNames.Id),
                ReadPreference = ReadPreference.Primary
            };

            return(_collection.FindOneAs <T>(findArgs) != null);
        }
Пример #2
0
        protected TModel FindOne <TModel>(OneOptions options) where TModel : class, new()
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            TModel result = null;

            if (options.UseCache)
            {
                result = Cache.Get <TModel>(GetScopedCacheKey(options.CacheKey));
            }

            if (result != null)
            {
                return(result);
            }

            var findArgs = new FindOneArgs {
                Query = options.GetQuery(_getIdValue), Fields = Fields.Include(options.Fields.ToArray()), SortBy = options.SortBy
            };

            if (options.ReadPreference != null)
            {
                findArgs.ReadPreference = options.ReadPreference;
            }

            result = _collection.FindOneAs <TModel>(findArgs);

            if (result != null && options.UseCache)
            {
                Cache.Set(GetScopedCacheKey(options.CacheKey), result, options.GetCacheExpirationDate());
            }

            return(result);
        }