Exemplo n.º 1
0
        public MongoGenericRepository(IMongoHelper mongoHelper)
        {
            var database       = mongoHelper.GetMongoDatabase();
            var collectionName = mongoHelper.GetMongoCollectionName <TEntity>();

            this.mongoHelper = mongoHelper;
            collection       = database.GetCollection <TEntity>(collectionName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Repository{TEntity, TId}"/> class.
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="collection">The collection.</param>
        /// <param name="indexes">The indexes.</param>
        public Repository(string connectionName, string collection, IEnumerable <MongoIndex> indexes)
        {
            _mongoHelper = MongoHelperProvider.Instance.GetHelper(connectionName);
            _collection  = collection;

            if (indexes == null || !indexes.Any())
            {
                return;
            }

            var mongoCollection = _mongoHelper.Repository.GetCollection <TEntity>(_collection);

            foreach (MongoIndex index in indexes)
            {
                mongoCollection.EnsureIndex(index.GetKey(), IndexOptions.SetName(index.Name));
            }
        }
Exemplo n.º 3
0
 public MongoLoggerHelper(IMongoHelper mongoHelper, IMongoLogger mongoLogger) : this()
 {
     _mongoHelper = mongoHelper;
     _mongoLogger = mongoLogger;
 }
Exemplo n.º 4
0
 public UploadService(IDomainService domainService, IMongoHelper <domain_file> dbHelper)
 {
     _domainService = domainService;
     _dbHelper      = dbHelper;
 }
Exemplo n.º 5
0
 public MongoLogger(IMongoHelper mongorHelper)
 {
     _mongoHelper     = mongorHelper;
     _mongoCollection = _mongoHelper.SetCollection("log");
 }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            imh = new MongoHelperFromEntity <Document>("Documents");
            #region Insert
            //for (int i = 1; i < 11; i++)
            //{
            //    if (imh.Insert(new Document("document" + i.ToString())) == null)
            //    {
            //        Response.Write("<script>alert('err')</script>");
            //        break;
            //    }
            //}
            //Response.Write("<script>alert('ok')</script>");
            #endregion
            #region Push
            //if (imh.Push("568231e7d6f684683c253f6a", d => d.Comment, new Comment("CN002", "Hi")))
            //{
            //    Response.Write("<script>alert('ok')</script>");
            //}
            //else
            //{
            //    Response.Write("<script>alert('err')</script>");
            //}
            #endregion
            #region Pull
            //if (imh.Pull<Comment>("568231e7d6f684683c253f6a", d => d.Comment, c => c.StaffID == "CN001"))
            //{
            //    Response.Write("<script>alert('ok')</script>");
            //}
            //else
            //{
            //    Response.Write("<script>alert('err')</script>");
            //}
            #endregion
            #region FindOne
            //Document doc = imh.FindOne("56822480d6f68424c8db56f2").Result;
            #endregion
            #region Find
            //string[] fields = { "Title" };
            //Dictionary<string, int> dicfields = new Dictionary<string, int>();
            //dicfields.Add("Time", 0);
            //List<Document> uu = imh.Find(fields, dicfields, u => u._id == "568231e7d6f684683c253f73").Result;
            #endregion
            #region Replace
            //if (imh.Replace("568231e7d6f684683c253f6a", new Document("document_replace")))
            //{
            //    Response.Write("<script>alert('ok')</script>");
            //}
            //else
            //{
            //    Response.Write("<script>alert('err')</script>");
            //}
            #endregion
            #region Update
            //Dictionary<string, object> dic = new Dictionary<string, object>();
            //dic.Add("Title", "document_update");
            //dic.Add("Time", DateTime.Now);
            //if (imh.Update("568231e7d6f684683c253f73", dic))
            //{
            //    Response.Write("<script>alert('ok')</script>");
            //}
            //else
            //{
            //    Response.Write("<script>alert('err')</script>");
            //}
            #endregion
            #region Delete
            if (imh.Delete("568231e7d6f684683c253f73"))
            {
                Response.Write("<script>alert('ok')</script>");
            }
            else
            {
                Response.Write("<script>alert('err')</script>");
            }
            #endregion
            //要注意的地方
            //1.是lambda准确

            //2.在构造对象时,如果这个对象是一个collection中的document时,一定要添加属性"_id",例如Model中Document中所示,在Insert时,_id不用赋值,后台会赋值,但是所用名称一定按照如下所示
            //private object id;
            //public object _id
            //{
            //    get { return id; }
            //    set { id = value; }
            //}

            //3.当对象中有List行属性时一定要付初值例如Model中Document中所示
            //private List<Comment> _Comment ;
            //public List<Comment> Comment
            //{
            //    get {
            //        if (_Comment == null) { _Comment = new List<Comment>(); }
            //        return _Comment;
            //    }
            //    set { _Comment = value; }
            //}

            //4.Pull操作中后面的对象为要插入到List中的对象

            //5.Web.config中mongodbConnection为MongoServer地址,可以使用;mongodbDatabase 为数据库名称,可以改成想要的
        }
Exemplo n.º 7
0
 public VeiculoDA()
 {
     mongoHelper =
         new MongoHelper <VeiculoEN, String>();
 }
Exemplo n.º 8
0
 public MongoRepository(IMongoHelper <TDocument> mongoHelper) : this(mongoHelper, null)
 {
 }
Exemplo n.º 9
0
 public MongoRepository(IMongoHelper <TDocument> mongoHelper, string collectionName)
 {
     _mongoHelper    = mongoHelper;
     _collectionName = collectionName;
 }
Exemplo n.º 10
0
 public MongoNewsRepository(IMongoHelper mongoHelper) : base(mongoHelper)
 {
 }
Exemplo n.º 11
0
 public MongoRepositoryBase(IMongoHelper mongoHelper) : this(mongoHelper, typeof(T).Name.ToLower() + "s")
 {
 }
Exemplo n.º 12
0
 public MongoRepositoryBase(IMongoHelper mongoHelper, string collectionName)
 {
     MongoHelper         = mongoHelper;
     this.collectionName = collectionName;
     //MongoHelper.SetIgnoreExtraElements<T>();  // some instances can be using a custom ClassMap
 }
Exemplo n.º 13
0
 public DomainService(IMongoHelper <domain> dbHelper)
 {
     _dbHelper = dbHelper;
 }
Exemplo n.º 14
0
 public ThemeService(IMongoHelper mongoHelper)
 {
     _themes = mongoHelper.GetCollection<ThemeDocument>("theme");
 }
Exemplo n.º 15
0
 public MongoLogsRepository(IMongoHelper mongoHelper, IDistributedCache cache) : base(mongoHelper)
 {
     this.cache = cache;
 }