MongoDB学习笔记(四)用MongoDB的文档结构描述数据关系(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:51 点击:次
/// 配置Mongo,将类UserInfo映射到集合
/// </summary>
private Mongo GetMongo()
{
var config = new MongoConfigurationBuilder();
config.Mapping(mapping =>
{
mapping.DefaultProfile(profile =>
{
profile.SubClassesAre(t => t.IsSubclassOf(typeof(UserInfo)));
});
mapping.Map<UserInfo>();
});
config.ConnectionString(connectionString);
return new Mongo(config.BuildConfiguration());
}
}
3. 接着,在“UserBLL”类中定义一个方法“InsertSomeData()”来插入一些数据:
/// <summary>
/// 插入一些数据
/// </summary>
public void InsertSomeData()
{
UserInfo userInfo1 = new UserInfo()
{
UserId = "1001",
UserName = "张三",
PassWord = "123456"
};
mongoCollection.Save(userInfo1);
UserInfo userInfo2 = new UserInfo()
{
UserId = "1002",
UserName = "李四",
PassWord = "123456",
Detail = new Detail()
{
Address = "湖北",
Age = 20,
Email = "lisi@163.com"
}
};
mongoCollection.Save(userInfo2);
UserInfo userInfo3 = new UserInfo()
{
UserId = "1003",
UserName = "王五",
PassWord = "123456",
Detail = new Detail()
{
Address = "广东",
Age = 20,
Email = "wangwu@163.com"
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>