Example #1
0
        public virtual bool IsUnique(TPrimaryKey id, string filedName, object value)
        {
            FilterDefinition <TEntity> filter;

            if (SoftDelete)
            {
                filter = Builders <TEntity> .Filter.And(Builders <TEntity> .Filter.Eq(filedName, value),
                                                        Builders <TEntity> .Filter.Eq(i => ((ISoftDelete)i).IsDeleted, false));
            }
            else
            {
                filter = Builders <TEntity> .Filter.Eq(filedName, value);
            }
            if (id != null && !string.IsNullOrWhiteSpace(id.ToString()))
            {
                filter = Builders <TEntity> .Filter.And(filter, Builders <TEntity> .Filter.Ne(m => m.Id, id));
            }
            var find = SlaveMongoCollection.Find(filter);

            return(find.FirstOrDefault() == null);
        }
Example #2
0
 public virtual long Count(Expression <Func <TEntity, bool> > filter)
 {
     return(SlaveMongoCollection.Find(SoftFilter(filter)).Count());
 }
Example #3
0
 public virtual TEntity FirstOrDefault(Expression <Func <TEntity, bool> > filter)
 {
     return(SlaveMongoCollection.Find(SoftFilter(filter)).FirstOrDefault());
 }
Example #4
0
 public virtual async Task <bool> AnyAsync(Expression <Func <TEntity, bool> > filter)
 {
     return(await SlaveMongoCollection.Find(SoftFilter(filter)).AnyAsync());
 }
Example #5
0
 public virtual IEnumerable <TEntity> FindAll(Expression <Func <TEntity, bool> > filter)
 {
     return(SlaveMongoCollection.Find(SoftFilter(filter)).ToList());
 }