MongoDB's official drive, syntax better, stronger
Previously wrote about Imongorepository warehousing, using norm on MongoDB's drive selection, but there was a problem with $ref reference type navigation, which was not very good for reference type property support. or using generics technology a few years ago instead of using attribute, the official driver did better in this respect, so I used the official driver and implemented a imongorepository, encapsulating some of the implementation details on the bottom, We call this official storage for mongoofficialrepository, hehe, who call you come late, mongorepository already for norm occupied, hehe.
New Imongorepository interface content added 4 methods
/// <summary> ///official drive, returns the result set with pagination/// </summary> /// <param name= "PageIndex" ></param> /// <param name= "pageSize" ></param> /// <returns></returns>Pagedresult<tentity> Getmodel (intPageIndex,intpageSize); /// <summary> ///official driver, returns the result set with conditions and pagination/// </summary> /// <param name= "expression" ></param> /// <param name= "PageIndex" ></param> /// <param name= "pageSize" ></param> /// <returns></returns>Pagedresult<tentity> Getmodel (expression<func<tentity,BOOL>> expression,intPageIndex,intpageSize); /// <summary> ///official driver, returns a result set with sorting and paging/// </summary> /// <param name= "Fields" ></param> /// <param name= "PageIndex" ></param> /// <param name= "pageSize" ></param> /// <returns></returns>Pagedresult<tentity> Getmodel (dictionary<expression<func<tentity,Object>>,BOOL> Fields,intPageIndex,intpageSize); /// <summary> ///official driver, returns the result set with conditions and sorting and pagination/// </summary> /// <param name= "expression" ></param> /// <param name= "Fields" ></param> /// <param name= "PageIndex" ></param> /// <param name= "pageSize" ></param> /// <returns></returns>Pagedresult<tentity> Getmodel (expression<func<tentity,BOOL>> expression, dictionary<expression<func<tentity,Object>>,BOOL> Fields,intPageIndex,intPageSize);
The implementation of the four methods, in order not to let MongoDB more details open, so, more cores can only be realized in the warehousing, hehe
PublicPagedresult<tentity> Getmodel (intPageIndex,intpageSize) { returnGetmodel (i =true, PageIndex, pageSize); } PublicPagedresult<tentity> Getmodel (system.linq.expressions.expression<func<tentity,BOOL>> expression,intPageIndex,intpageSize) { returnGetmodel (expression,NewDictionary<expression<func<tentity,Object>>,BOOL>(), PageIndex, pageSize); } PublicPagedresult<tentity>Getmodel (Dictionary<expression<func<tentity,Object>>,BOOL>Fields ,intPageIndex,intpageSize) { returnGetmodel (i =true, Fields, PageIndex, pageSize); } PublicPagedresult<tentity>Getmodel (Expression<func<tentity,BOOL>>expression, Dictionary<expression<func<tentity,Object>>,BOOL>Fields ,intPageIndex,intpageSize) {sortdefinition<TEntity> sorts =NewObjectsortdefinition<tentity> (New { }); foreach(varIteminchFields ) { if(item. Value) Sorts=sorts. Ascending (item. Key); ElseSorts=sorts. Descending (item. Key); } varSkip = (PageIndex-1) *pageSize; varLimit =pageSize; varRecordCount = _table. countasync<tentity> (i =true). Result; return NewPagedresult<tentity>(RecordCount, (int) (RecordCount + pageSize-1) /pageSize, PageSize, PageIndex, _table. Find (expression). Sort (sorts). Skip (Skip). Limit (limit). Tolistasync (). Result); }
OK, now you can call it in the business layer, the basic above four methods can meet all your needs, hehe!
Look at the UI layer on its call, this demo does not have a BLL layer, hehe
// //GET:/background/ PublicActionResult Index (intSort =0,intpage =1) {Dictionary<expression<func<webmanageusers,Object>>,BOOL> sortlist =NewSystem.collections.generic.dictionary<expression<func<webmanageusers,Object>>,BOOL>(); Sortlist.add (i= = I.loginname, sort = =0); varModel = _webmanageusersrepository.getmodel (Sortlist,page,Ten); returnView (model); }
How to see the above code whether the heart itch, haha, quickly go to develop your own MONGODB warehousing it!
MongoDB Learning Notes ~ added sorting and expression trees to the Imongorepository interface for the official drive