コード例 #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));
 }
コード例 #2
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)));
 }
コード例 #3
0
 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()));
 }
コード例 #4
0
        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());
        }
コード例 #5
0
 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));
 }
コード例 #6
0
        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));
        }
コード例 #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);
        }
コード例 #8
0
 /// <summary>
 /// 移除文件
 /// </summary>
 /// <param name="id">文件id</param>
 public static void RemoveFile <TMongoFileType>(string id) where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBRemoveGridFS <TMongoFileType>((BsonValue)id);
 }
コード例 #9
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));
 }
コード例 #10
0
 /// <summary>
 /// 移除所有实例
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <returns></returns>
 public static long RemoveAll <T>() where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBRemoveAll <T>());
 }
コード例 #11
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));
 }
コード例 #12
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));
 }
コード例 #13
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));
 }
コード例 #14
0
 public static List <T> GetAll <T>() where T : IEntity
 {
     IsTypeCanBeUsed(typeof(T));
     return(EntityOperationExtensions.DBFindAll <T>());
 }
コード例 #15
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);
 }
コード例 #16
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);
 }
コード例 #17
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));
 }
コード例 #18
0
 /// <summary>
 /// 合计
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <returns></returns>
 public static long Count <T>() where T : IEntity
 {
     return(EntityOperationExtensions.DBCount <T>());
 }
コード例 #19
0
 /// <summary>
 /// 移除所有文件(慎用)
 /// </summary>
 public static void RemoveAllFiles <TMongoFileType>() where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBRemoveAllGridFS <TMongoFileType>();
 }
コード例 #20
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));
 }
コード例 #21
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);
 }
コード例 #22
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);
 }
コード例 #23
0
 /// <summary>
 /// 移除文件
 /// </summary>
 /// <param name="remoteFileName">存储文件名</param>
 public static void RemoveFiles <TMongoFileType>(string remoteFileName) where TMongoFileType : IMongoFile
 {
     EntityOperationExtensions.DBRemoveGridFS <TMongoFileType>(remoteFileName);
 }
コード例 #24
0
 public virtual void Save()
 {
     //this.DBSave();
     EntityOperationExtensions.DBSave(this.GetType(), this);
 }