示例#1
0
 /// <summary>
 ///     Insert New Document
 /// </summary>
 /// <typeparam name="T">Entity "T"</typeparam>
 /// <param name="o"></param>
 /// <returns>newdocument'id</returns>
 public int Insert <T>(T o)
 {
     try
     {
         Type t = typeof(T);
         MongoCollection <BsonDocument> coll = BaseDB.CreateInstance().GetCollection(t.Name);
         int seq = BaseDB.GetSeqence("Seqence" + t.Name);
         o.GetType().GetProperty("_id").SetValue(o, seq, null);
         coll.Insert(o);
         return(seq);
     }
     catch
     {
         return(0);
     }
     finally
     {
         BaseDB.MongoService.Disconnect();
     }
 }
示例#2
0
        /// <summary>
        ///     Insert New Document Collectionss
        /// </summary>
        /// <typeparam name="T">Entity Collections "T"</typeparam>
        /// <param name="os"></param>
        /// <returns></returns>
        public bool Insert <T>(IEnumerable <T> os)
        {
            try
            {
                Type t = typeof(T);
                MongoCollection <BsonDocument> coll = BaseDB.CreateInstance().GetCollection(t.Name);

                foreach (T o in os)
                {
                    int seq = BaseDB.GetSeqence("Seqence" + t.Name);
                    o.GetType().GetProperty("_id").SetValue(o, seq, null);
                    coll.Insert(o);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                BaseDB.MongoService.Disconnect();
            }
        }