开通《金牌VIP》,全站所有资源均可免积分下载!
首页 其他源码 分类错误 正文

c# mongodb实例源码(asp.net mvc实现)

  • 资源分类:分类错误
  • 发 布 人:admin
  • 文件大小:未知
  • 文件格式:
  • 浏览次数:34

  • 发布时间:2022.9.4
  • 下载次数: 3
  • 标签: mongodbMVC

链接失效怎么办?如遇链接失效请在资源下留言,24小时处理
广告位2
声明:『找例子网』为本站子站,因特殊原因不再运营,相关源码例子均纳入本站源码例子专栏

实现了 对mongodb数据库的增删改 操作
using System;using System.Collections.Generic;using System.Linq;using System.Web;using MongoDBMVC3.Models;using MongoDB;namespace MongoDBMVC3.Biz{ public class BizModel { public static Channel GetChannelbyID(Guid cid) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); var query = from c in list.Linq() select c; Channel channel = query.Where(c => c.ChannelId == cid).First(); return channel; } } public static List<Channel> GetChannel() { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); var query = (from c in list.Linq() select c).ToList<Channel>(); return query; } } public static void AddChannel(Channel model) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); list.Insert(model); } } public static void UpdateChannel(Channel model) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); list.Update(model, c => c.ChannelId == model.ChannelId); } } public static void DeleteChannel(Guid cid) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); list.Remove(c => c.ChannelId == cid); } } }}

相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复

'