示例#1
0
        public virtual async Task <bool> IsUniqueAsync(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 = await SlaveMongoCollection.FindAsync(filter);

            return(find.FirstOrDefault() == null);
        }
示例#2
0
        public virtual async Task <TEntity> FirstOrDefaultAsync(Expression <Func <TEntity, bool> > filter)
        {
            var x = await SlaveMongoCollection.FindAsync(SoftFilter(filter));

            return(x.FirstOrDefault());
        }
示例#3
0
        public virtual async Task <IEnumerable <TEntity> > FindAllAsync(Expression <Func <TEntity, bool> > filter)
        {
            var x = await SlaveMongoCollection.FindAsync(SoftFilter(filter));

            return(x.ToList());
        }