本篇是作为另一篇随笔的一部分‘搭建一个Web API项目’
MogonDB官网:https://www.mongodb.org/
安装过程参考园友的分享http://www.cnblogs.com/lzrabbit/p/3682510.html
cmd client:
C:\Users\Administrator>D:
D:\> cd D:\MongoDB\Server\3.2\bin
D:\MongoDB\Server\3.2\bin>mongo 127.0.0.1:27017
>use zheyibu
>db.SEOStudent.find()
1 /// <summary> 2 /// MongoDB支持的实体,必须要有Id 3 /// </summary> 4 public interface IEntity 5 { 6 [BsonId] 7 int Id { get; set; } 8 }
1 /// <summary> 2 /// 3 /// </summary> 4 public class SEOStudent : IEntity 5 { 6 /// <summary> 7 /// 8 /// </summary> 9 public int Id { get; set; } 10 11 public string Name { get; set; } 12 13 }
二、项目Frozen.MongoCommon
(这部分的代码都是从园子里拷下来的,望大神们莫怪!本文不用于任何商业用途!)
IMongoDBRepositoryContextSettings
1 using MongoDB.Driver; 2 3 namespace Frozen.MongoCommon 4 { 5 /// <summary> 6 /// Represents that the implemented classes are MongoDB repository context settings. 7 /// </summary> 8 public interface IMongoDBRepositoryContextSettings 9 { 10 /// <summary> 11 /// Gets the database name. 12 /// </summary> 13 string DatabaseName { get; } 14 /// <summary> 15 /// Gets the instance of <see cref="MongoServerSettings"/> class which represents the 16 /// settings for MongoDB server. 17 /// </summary> 18 MongoClientSettings ClientSettings { get; } 19 /// <summary> 20 /// Gets the instance of <see cref="MongoDatabaseSettings"/> class which represents the 21 /// settings for MongoDB database. 22 /// </summary> 23 /// <param name="server">The MongoDB server instance.</param> 24 /// <returns>The instance of <see cref="MongoDatabaseSettings"/> class.</returns> 25 MongoDatabaseSettings GetDatabaseSettings(MongoClient client); 26 27 } 28 }