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); }
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); }