Ejemplo n.º 1
0
 /// <summary>
 /// 分页查询
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="where">查询表达式</param>
 /// <param name="orderby">排序</param>
 /// <param name="pageIndex">页码</param>
 /// <param name="pageSize">单页容量</param>
 /// <param name="pageCount">总页数</param>
 /// <param name="allCount">总条目数</param>
 /// <returns></returns>
 public static IQueryable <T> Select <T>(Expression <Func <T, bool> > where, Expression <Func <T, object> > orderby, int pageIndex, int pageSize, out int pageCount, out int allCount) where T : IEntity
 {
     pageCount = 0;
     allCount  = 0;
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBSelect <T>(where, orderby, pageIndex, pageSize, out pageCount, out allCount));
 }
 public static T Instance <T>(this MongoDBRef instance) where T : IEntity
 {
     if (instance == null || null == instance.Id || string.IsNullOrEmpty(instance.CollectionName))
     {
         return(default(T));
     }
     return(EntityOperationExtensions.DBFind <T>(instance.Id.ToString()));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 加载一个GridFS文件
 /// </summary>
 /// <param name="id">文件id</param>
 /// <returns></returns>
 public static IMongoFile LoadFile <TMongoFileType>(string id) where TMongoFileType : IMongoFile
 {
     if (!id.IsMongoId())
     {
         return(null);
     }
     return(new MongoFile <TMongoFileType>(EntityOperationExtensions.DBLoadGridFS <TMongoFileType>((BsonValue)id)));
 }
        public static List <T> RefPick <T>(this List <MongoDBRef> lst) where T : IEntity
        {
            if (lst == null)
            {
                return(new List <T>());
            }
            var ids = lst.Where(i => i.CollectionName == typeof(T).DBCollectionName()).Select(i => i.Id).ToArray();

            return(EntityOperationExtensions.DBSelect <T>(i => ids.Contains(i.Id)).ToList());
        }
 public static T RefPick <T>(this List <MongoDBRef> lst, string id) where T : IEntity
 {
     if (lst == null)
     {
         return(default(T));
     }
     if (!lst.Exists(l => l.Id == id && l.CollectionName == typeof(T).DBCollectionName()))
     {
         return(default(T));
     }
     return(EntityOperationExtensions.DBFind <T>(id));
 }
        public static bool RefExists <T>(this List <MongoDBRef> lst, Expression <Func <T, bool> > where) where T : IEntity
        {
            if (lst == null)
            {
                return(false);
            }
            var ids = lst.Where(i => i.CollectionName == typeof(T).DBCollectionName()).Select(i => i.Id).ToArray();

            if (ids.Length == 0)
            {
                return(false);
            }
            return(EntityOperationExtensions.DBSelect <T>(i => ids.Contains(i.Id)).All(where));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载文件集
        /// </summary>
        /// <param name="remoteFileName">存储文件名</param>
        /// <returns></returns>
        public static List <IMongoFile> LoadAllFiles <TMongoFileType>(string remoteFileName) where TMongoFileType : IMongoFile
        {
            List <IMongoFile> files = new List <IMongoFile>();

            if (string.IsNullOrEmpty(remoteFileName))
            {
                return(files);
            }
            var infos = EntityOperationExtensions.DBLoadGridFS <TMongoFileType>(remoteFileName);

            if (infos.Count == 0)
            {
                return(files);
            }
            infos.ForEach(delegate(MongoGridFSFileInfo info)
            {
                files.Add(new MongoFile <TMongoFileType>(info));
            });
            return(files);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 移除文件
 /// </summary>
 /// <param name="remoteFileName">存储文件名</param>
 public static void RemoveFiles <TMongoFileType>(string remoteFileName) where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBRemoveGridFS <TMongoFileType>(remoteFileName);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 合计
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <returns></returns>
 public static long Count <T>() where T : IEntity
 {
     return(EntityOperationExtensions.DBCount <T>());
 }
Ejemplo n.º 10
0
 public virtual void Save()
 {
     //this.DBSave();
     EntityOperationExtensions.DBSave(this.GetType(), this);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 移除所有实例
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <returns></returns>
 public static long RemoveAll <T>() where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBRemoveAll <T>());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 移除一个实例
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="id">id</param>
 /// <returns></returns>
 public static bool Remove <T>(string id) where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBRemove <T>(id));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 获取一个实例
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="where">查询表达式</param>
 /// <returns></returns>
 public static T Get <T>(Expression <Func <T, bool> > where) where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBFind <T>(where));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 获取一个实例
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="id">id</param>
 /// <returns></returns>
 public static T Get <T>(string id) where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBFind <T>(id));
 }
Ejemplo n.º 15
0
 public static List <T> GetAll <T>() where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBFindAll <T>());
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 下载文件
 /// </summary>
 /// <param name="id">文件id</param>
 /// <param name="stream">文件流</param>
 public static void DownloadFile <TMongoFileType>(string id, Stream stream) where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBDownloadGridFS <TMongoFileType>(id, stream);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="where">查询表达式</param>
 /// <returns></returns>
 public static IQueryable <T> Select <T>(Expression <Func <T, bool> > where) where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBSelect <T>(where));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// 合计
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="where">查询表达式</param>
 /// <returns></returns>
 public static long Count <T>(Expression <Func <T, bool> > where) where T : IEntity
 {
     return(EntityOperationExtensions.DBCount <T>(where));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// 移除文件
 /// </summary>
 /// <param name="id">文件id</param>
 public static void RemoveFile <TMongoFileType>(string id) where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBRemoveGridFS <TMongoFileType>((BsonValue)id);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 移除所有文件(慎用)
 /// </summary>
 public static void RemoveAllFiles <TMongoFileType>() where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBRemoveAllGridFS <TMongoFileType>();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 保存
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="entity">实体</param>
 public static void Save <T>(T entity) where T : IEntity
 {
     EntityOperationExtensions.DBSave(typeof(T), entity);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// 批量插入(已存在则不插入)
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="entities">实例集合</param>
 public static void InsertBatch <T>(List <T> entities) where T : IEntity
 {
     EntityOperationExtensions.DBInsertBatch <T>(entities);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// 下载文件
 /// </summary>
 /// <param name="id">文件id</param>
 /// <param name="localFileName">本地路径(绝对路径)</param>
 public static void DownloadFile <TMongoFileType>(string id, string localFileName) where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBDownloadGridFS <TMongoFileType>(id, localFileName);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// 移除所有实例
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="where">查询表达式</param>
 /// <returns></returns>
 public static long RemoveAll <T>(Expression <Func <T, bool> > where) where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBRemoveAll <T>(where));
 }