Home Database Mysql Tutorial MongoDB结合Flexgrid的简单数据呈现

MongoDB结合Flexgrid的简单数据呈现

Jun 07, 2016 pm 05:56 PM
mongodb data Simple combine

MongoDB结合Flexgrid的简单数据呈现 本示例以常用的:用户,帖子,评论为基础模型,实现了一个简单的MongoDB结合Flexgrid数据呈现的Demo。由于时间所限,功能上仅提供对MongoDB数据的常用查询操作(分页,排序,查询等)。高手请对我这种菜鸟多些包容。 一,

MongoDB结合Flexgrid的简单数据呈现

 

本示例以常用的:用户,帖子,评论为基础模型,实现了一个简单的MongoDB结合Flexgrid数据呈现的Demo。由于时间所限,功能上仅提供对MongoDB数据的常用查询操作(分页,排序,查询等)。高手请对我这种菜鸟多些包容。

 

一,准备工作:

MongoDB官方下载:

当前最新版本是2.2.0版本。话说,MongoDB的版本更新是相当的快。

 

本示例使用的MongoDB C#版驱动下载:
https://github.com/samus/mongodb-csharp
该驱动附源码和示例程序,有兴趣的朋友可以研究一下,对自己的编码能力会有很大的提高。用VS打开Source文件夹,编译后得到程序集,在自己的项目中引用即可。

 

这是官方邮件提供的 C#版驱动:
https://github.com/mongodb/mongo-csharp-driver/downloads
版本很多,而且基本上都是十多兆的东西,然后,没有然后。

 

如果你不习惯以命令行的方式对MongoDB进行操作和管理。推荐以下客户端管理工具:
1,MongoVUE。这应该是目前应用最广的了。
下载地址:

2,虚拟主机,博客园高手自己开发的MongoDB管理工具:

试用了一下,也是相当不错的!

 

虽然上述管理工具能够以图形化的方式与MongoDB交互,但强烈建议你运行mongo.exe客户端,以命令行的方式对MongoDB进行操作和管理,这会让你对MongoDB有更加直观而深刻的体会。另外,Windows8依然内置了DOS。

 

这里有MongoDB的常用命令:

 

这是Flexgrid的官方网站:

页面顶部有一个硕大的红色Download按钮。

 

TestDriven.net,必不可少的开发和测试工具。本示例需要用它向MongoDB中初始化测试数据。下载地址:

 

二,项目结构:

麻雀虽小,五脏俱全。整个项目结构是一个最原始的三层。直接上图:

三,技术细节:

1,MongoDB数据库操作。
ADO.NET虽然很强大,但我们通常需要自己动手写一个SqlHelper。MongoDB也一样,我们仍有必要在驱动的基础上对常用的数据操作进行封装。下面贴出本鸟写的MongoDB数据库操作类。大多数方法都与数据查询相关。贴出主要代码:

using System; using System.Collections.Generic; using System.Linq; using System.Configuration; using MongoDB; using MongoDB.Linq; using Mcmurphy.Commons.Enumerations; namespace Mcmurphy.DAL { public class MongoDBHelper { #region 基本信息 private static readonly string ConnectionString; private static readonly string DatabaseName; ///

/// 当前Mongo引用 /// private static Mongo mongo; /// /// 初始化数据库配置 /// static MongoDBHelper() { ConnectionString = ConfigurationManager.AppSettings["connString"]; DatabaseName = ConfigurationManager.AppSettings["currentDB"]; } /// /// 当前Mongo对象 /// private static Mongo CurrentMongo { get { return new Mongo(ConnectionString); } } /// /// 当前操作集合 /// private static IMongoCollection GetCollection() where T:class { try { mongo = CurrentMongo; mongo.Connect(); IMongoDatabase db = GetCurrentDataBase(); IMongoCollection collection = db.GetCollection(); return collection; } catch (Exception ex) { throw ex; } } /// /// 获取当前Mongo数据库对象 /// /// 当前Mongo数据库对象 private static IMongoDatabase GetCurrentDataBase() { return mongo.GetDatabase(DatabaseName); } #endregion #region 数据查询 /// /// 获取排序规则 /// private static IndexOrder GetIndexOrder(DataOrder order) { IndexOrder @orderby = order == DataOrder.Ascending ? IndexOrder.Ascending : IndexOrder.Descending; return orderby; } /// /// 根据条件进行查询,并进行分页 /// /// 类型参数 /// 条件Lamda表达式 /// 当前页索引 /// 分页大小 /// 结果集 public static IEnumerable GetBySearch(System.Linq.Expressions.Expression> selector, int pageIndex, int pageSize) where T : class { try { var currentCollection = GetCollection(); return currentCollection.Find(selector).Skip((pageIndex - 1) * pageSize).Limit(pageSize).Documents.ToList(); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } /// /// 根据条件进行查询,并进行分页和排序 /// /// 类型参数 /// 条件Lamda表达式 /// 当前页索引 /// 分页大小 /// 排序规则 /// 排序字段 /// 结果集 public static IEnumerable GetBySearch(System.Linq.Expressions.Expression> selector, int pageIndex, int pageSize, DataOrder order, string orderField) where T : class { try { IndexOrder orderby = GetIndexOrder(order); var currentCollection = GetCollection(); return currentCollection.Find(selector).Sort(orderField, orderby).Skip((pageIndex - 1) * pageSize).Limit(pageSize).Documents.ToList(); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } /// /// 根据条件查询一个对象 /// /// 类型参数 /// 查询条件Lamda表达式 /// 查询对象 public static T GetOneBySearch(System.Linq.Expressions.Expression> selector) where T : class { try { var currentCollection = GetCollection(); return currentCollection.FindOne(selector); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } /// /// 根据查询条件获取总记录数 /// /// 类型参数 /// 查询条件 /// 记录数 public static long GetTotalCount(System.Linq.Expressions.Expression> selector) where T : class { try { var currentCollection = GetCollection(); return currentCollection.Count(selector); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } /// /// 获取总记录数 /// /// 类型参数 /// 记录数 public static long GetTotalCount() where T : class { try { var currentCollection = GetCollection(); return currentCollection.Count(); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } #endregion #region 数据插入 /// /// 数据插入 /// /// 类型参数 /// 要插入的数据对象 public static void Insert(T t) where T : class { try { var currentCollection = GetCollection(); currentCollection.Insert(t); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } #endregion #region 数据更新 /// /// 根据查询条件更新数据 /// /// 类型参数 /// 待更新的对象 /// 更新的条件Lamda表达式 public static void Update(T t, System.Linq.Expressions.Expression> selector) where T : class { try { var currentCollection = GetCollection(); currentCollection.Update(t,selector); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } /// /// 更新/插入数据(id是否存在) /// /// 类型参数 /// 待更新的对象 public static void Update(T t) where T : class { try { var currentCollection = GetCollection(); //inserts of updates depends on whether id exists currentCollection.Save(t); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } #endregion #region 数据删除 /// /// 数据删除 /// /// 类型参数 /// 查询的条件Lamda表达式 public static void Delete(System.Linq.Expressions.Expression> selector) where T : class { try { var currentCollection = GetCollection(); currentCollection.Remove(selector); } catch (Exception ex) { throw ex; } finally { mongo.Disconnect(); mongo.Dispose(); } } #endregion } }

初次调用的时候,会读取在站点项目下Web.Config文件中配置的数据库服务器地址以及数据库名称。

 

2,Flexgrid加载的数据格式。
在官网上徘徊了很久也没有找到Flexgrid要求的数据格式说明。还好有Firebug,但遗憾的是官方示例采用的是XML格式。如下:

  1  234           ...      ...

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Which version is generally used for mongodb? Which version is generally used for mongodb? Apr 07, 2024 pm 05:48 PM

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source Apr 29, 2024 pm 04:55 PM

FP8 and lower floating point quantification precision are no longer the "patent" of H100! Lao Huang wanted everyone to use INT8/INT4, and the Microsoft DeepSpeed ​​team started running FP6 on A100 without official support from NVIDIA. Test results show that the new method TC-FPx's FP6 quantization on A100 is close to or occasionally faster than INT4, and has higher accuracy than the latter. On top of this, there is also end-to-end large model support, which has been open sourced and integrated into deep learning inference frameworks such as DeepSpeed. This result also has an immediate effect on accelerating large models - under this framework, using a single card to run Llama, the throughput is 2.65 times higher than that of dual cards. one

2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th 2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th Apr 18, 2024 pm 09:04 PM

The 2024QS World University Rankings by Subject is here! Overall, there is little change from 2023. According to the official website information, the 2024QS World University Rankings by Subject covers 55 subdivisions and 5 major academic fields. A total of 1,559 universities participated in the ranking, 64 of which are new faces this year (that is, they will not appear in the 2023 ranking). Among these 64 colleges and universities, 14 are truly appearing for the first time. Among them is the University of Chinese Academy of Sciences. According to the refined subjects, Music is a new subject introduced this year. In addition, the data science and artificial intelligence rankings have been expanded, with 51 new universities added to the rankings. The top five in the overall list are: Massachusetts Institute of Technology, University of Cambridge, University of Oxford, and Harvard University

See all articles