当前位置: 首页>>代码示例>>C#>>正文


C# MongoRepository.Add方法代码示例

本文整理汇总了C#中MongoRepository.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository.Add方法的具体用法?C# MongoRepository.Add怎么用?C# MongoRepository.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoRepository的用法示例。


在下文中一共展示了MongoRepository.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FirstDBTest

 public void FirstDBTest()
 {
     using (var db = new MongoRepository<DBStub>())
     {
         db.Add(new DBStub() { Name = "test" });
     }
 }
开发者ID:enjoyeclipse,项目名称:PackageTravel,代码行数:7,代码来源:DBTestStub.cs

示例2: ImportCpus

        private void ImportCpus()
        {
            int[] cpuCores = { 2, 3, 4, 6 };

            IRepository<Cpu> cpuRepository = new MongoRepository<Cpu>(this.dbContext);
            IRepository<Vendor> vendorRepository = new MongoRepository<Vendor>(this.dbContext);
            var vendorsList = vendorRepository.GetAll().ToList();

            textWriter.Write("Importing CPUs");

            for (int i = 0; i < 42; i++)
            {
                if (i % 2 == 0)
                {
                    textWriter.Write(".");
                }

                int currentCpuCoresCount = cpuCores[RandomUtils.GenerateNumberInRange(0, cpuCores.Length - 1)];
                cpuRepository.Add(new Cpu()
                {
                    Id = ObjectId.GenerateNewId(),
                    Cores = currentCpuCoresCount,
                    Model = RandomUtils.GenerateRandomString(RandomUtils.GenerateNumberInRange(2, 5)),
                    Price = currentCpuCoresCount * RandomUtils.GenerateNumberInRange(100, 120),
                    VendorId = vendorsList[RandomUtils.GenerateNumberInRange(0, vendorsList.Count - 1)].Id
                });
            }

            textWriter.WriteLine();
        }
开发者ID:TeamBromine,项目名称:Main,代码行数:30,代码来源:MongoImporter.cs

示例3: TestCountOne

        public void TestCountOne()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);
            repository.Add(new ClassTest());

            var count = repository.Count();

            Assert.AreEqual(1, count);
        }
开发者ID:nchistyakov,项目名称:MongoRepository,代码行数:9,代码来源:RepositoryTests.cs

示例4: test_child_collection_match_using_any

        public void test_child_collection_match_using_any()
        {
            var mongoRepository = new MongoRepository<User>(collection: "UserCollection");
            mongoRepository.RemoveAll();
            mongoRepository.Linq().ToList().Should().BeEmpty();

            var user = new User()
            {
                Name = "1",
                Accounts = new List<Account>()
                {
                    new Account()
                    {
                        Name = "a1",
                        Prop2 = "p1"
                    }
                }
            };

            var user2 = new User()
            {
                Name = "2",
                Accounts = new List<Account>()
                {
                    new Account()
                    {
                        Name = "a2",
                        Prop2 = "p2"
                    }
                }
            };

            mongoRepository.Add(user);
            mongoRepository.Add(user2);
            mongoRepository.Linq().ToList().Should().HaveCount(2);

            var match =
                mongoRepository.Linq().SingleOrDefault(x => x.Accounts.Any(a => a.Name == "a1" && a.Prop2 == "p1"));
            match.Should().NotBeNull();
        }
开发者ID:detroitpro,项目名称:ProMongoRepository,代码行数:40,代码来源:Collection_Tests.cs

示例5: Get_WhenObjectId_IsObjectId_ReturnsUser

        public void Get_WhenObjectId_IsObjectId_ReturnsUser()
        {
            //arrange
            var mongoRepository = new MongoRepository<User>();
            var user = new User() { Name = "Get_WhenObjectId_IsObjectId_ReturnsUser" };
            user = mongoRepository.Add(user);

            //act
            var found = mongoRepository.Get(user.Id);

            //assert
            found.Should().NotBeNull();
            found.Name.Should().Be(user.Name);
            found.Id.Should().Be(user.Id);
        }
开发者ID:detroitpro,项目名称:ProMongoRepository,代码行数:15,代码来源:Examples.cs

示例6: AddAndUpdateTest

        public void AddAndUpdateTest()
        {
            IRepository<Customer> _customerRepo = new MongoRepository<Customer>();
            IRepositoryManager<Customer> _customerMan = new MongoRepositoryManager<Customer>();

            Assert.IsFalse(_customerMan.Exists);

            var customer = new Customer();
            customer.FirstName = "Bob";
            customer.LastName = "Dillon";
            customer.Phone = "0900999899";
            customer.Email = "[email protected]";
            customer.HomeAddress = new Address
            {
                Address1 = "North kingdom 15 west",
                Address2 = "1 north way",
                PostCode = "40990",
                City = "George Town",
                Country = "Alaska"
            };

            _customerRepo.Add(customer);

            Assert.IsTrue(_customerMan.Exists);

            Assert.IsNotNull(customer.Id);

            // fetch it back
            var alreadyAddedCustomer = _customerRepo.Where(c => c.FirstName == "Bob").Single();

            Assert.IsNotNull(alreadyAddedCustomer);
            Assert.AreEqual(customer.FirstName, alreadyAddedCustomer.FirstName);
            Assert.AreEqual(customer.HomeAddress.Address1, alreadyAddedCustomer.HomeAddress.Address1);

            alreadyAddedCustomer.Phone = "10110111";
            alreadyAddedCustomer.Email = "[email protected]";

            _customerRepo.Update(alreadyAddedCustomer);

            // fetch by id now
            var updatedCustomer = _customerRepo.GetById(customer.Id);

            Assert.IsNotNull(updatedCustomer);
            Assert.AreEqual(alreadyAddedCustomer.Phone, updatedCustomer.Phone);
            Assert.AreEqual(alreadyAddedCustomer.Email, updatedCustomer.Email);

            Assert.IsTrue(_customerRepo.Exists(c => c.HomeAddress.Country == "Alaska"));
        }
开发者ID:rodolfofadino,项目名称:MongoRepository-Fork,代码行数:48,代码来源:RepoTests.cs

示例7: AddSprint

        public void AddSprint()
        {
            var repo = new MongoRepository<Concert>();

            var newSprint = new Concert
                {
                    Artist = new Artist
                    {
                        Name = "Eddie Meduza"
                    }
                };

            repo.Add(newSprint);

            var sprint = repo.All(c => c.Artist.Name == "Eddie Meduza");

            Assert.That(sprint, Is.EqualTo(newSprint));
        }
开发者ID:tantudor,项目名称:live.history,代码行数:18,代码来源:SprintRepoTest.cs

示例8: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            MongoRepository.MongoRepository<Basla> repo = new MongoRepository<Basla>();
            repo.DeleteAll();
            Basla b = new Basla();
            FlowAction a = new FlowAction();
            b.SonrakiEleman = a;
            repo.Add(b);

            var txxx = repo.Where(t => t.Id != null).ToList();

        }
开发者ID:kanpinar,项目名称:WorkFlowMania,代码行数:19,代码来源:Global.asax.cs

示例9: TestCountOne

        public void TestCountOne()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);

            var classTest = new ClassTest()
                {
                    IntProperty = 10,
                    ChildClassTests = new List<ChildClassTest>()
                        {
                            new ChildClassTest() {StringProperty = "first string"},
                            new ChildClassTest() {StringProperty = "second string"}
                        }
                };

            repository.Add(classTest);

            var count = repository.Count();

            Assert.AreEqual(1, count);
        }
开发者ID:nchistyakov,项目名称:MongoRepository,代码行数:20,代码来源:ComplexRepositoryTests.cs

示例10: AddFacebookUserHome

        private void AddFacebookUserHome(string UserId, FacebookClient fb, dynamic profile)
        {
            int K = 0;

            Domain.Socioboard.MongoDomain.FacebookMessage objFacebookMessage = new Domain.Socioboard.MongoDomain.FacebookMessage();
            try
            {
                dynamic home = fb.Get("v2.0/me/home");
                if (home != null)
                {
                    int lstfbcount = 0;
                    foreach (dynamic result in home["data"])
                    {
                        string message = string.Empty;
                        string imgprof = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                        objFacebookMessage.EntryDate = DateTime.UtcNow.ToString();
                        objFacebookMessage.MessageId = result["id"].ToString();
                        objFacebookMessage.FromId = result["from"]["id"].ToString();
                        objFacebookMessage.FromName = result["from"]["name"].ToString();
                        objFacebookMessage.FromProfileUrl = imgprof;
                        objFacebookMessage.Id = ObjectId.GenerateNewId();
                        objFacebookMessage.MessageDate = DateTime.Parse(result["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                        objFacebookMessage.UserId =UserId;

                        try
                        {
                            objFacebookMessage.Picture = result["picture"].ToString();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                            objFacebookMessage.Picture = null;
                        }
                        try
                        {
                            if (result["message_tags"][0] != null)
                            {
                                if (result["to"] != null)
                                {
                                    foreach (var item in result["to"]["data"])
                                    {
                                        if (result["from"] != null)
                                        {

                                            if (item["id"] != profile["id"])
                                            {
                                                if (result["from"]["id"] == profile["id"])
                                                {
                                                    objFacebookMessage.Type = "fb_tag";
                                                }
                                                else
                                                {
                                                    objFacebookMessage.Type = "fb_home";
                                                }
                                            }
                                            else
                                            {
                                                objFacebookMessage.Type = "fb_home";
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    objFacebookMessage.Type = "fb_home";

                                }
                            }
                            else
                            {
                                objFacebookMessage.Type = "fb_home";
                            }
                        }
                        catch (Exception ex)
                        {
                            objFacebookMessage.Type = "fb_home";
                            Console.WriteLine(ex.StackTrace);
                        }
                        objFacebookMessage.ProfileId = profile["id"].ToString();
                        objFacebookMessage.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                        dynamic likes = fb.Get("v2.0/" + result["id"].ToString() + "/likes?limit=50000000");
                        string likestatus = "likes";
                        foreach (dynamic like in likes["data"])
                        {
                            try
                            {
                                if (profile["id"].ToString() == like["id"].ToString())
                                {
                                    likestatus = "unlike";
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                likestatus = "likes";

                            }
                        }
                        objFacebookMessage.FbLike = likestatus;
//.........这里部分代码省略.........
开发者ID:ShiftCtrlGroup,项目名称:socioboard-core,代码行数:101,代码来源:Facebook.asmx.cs

示例11: AddFacebookMessageWithPagination

        //Added by Sumit Gupta [02-02-15]
        private void AddFacebookMessageWithPagination(string UserId, FacebookClient fb, dynamic profile)
        {
            int J = 0;
            Domain.Socioboard.MongoDomain.FacebookMessage objFacebookMessage = new Domain.Socioboard.MongoDomain.FacebookMessage();
            try
            {
                string nexturl = "v2.0/me/inbox";

                for (int i = 0; i < 50; i++)
                {
                    dynamic messages = fb.Get(nexturl);
                    if (messages != null)
                    {
                        try
                        {
                            nexturl = messages["paging"]["next"].ToString();
                            logger.Error("Facebook.asmx >> AddFacebookMessageWithPagination >> nexturl : " + nexturl);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                            logger.Error(ex.StackTrace);
                        }

                        foreach (dynamic result in messages["data"])
                        {
                            try
                            {
                                foreach (dynamic message in result["comments"]["data"])
                                {
                                    objFacebookMessage.MessageId = message["id"];
                                    objFacebookMessage.FromName = message["from"]["name"];
                                    objFacebookMessage.FromId = message["from"]["id"];
                                    objFacebookMessage.Message = message["message"];
                                    objFacebookMessage.MessageDate = DateTime.Parse(message["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                                    objFacebookMessage.FromProfileUrl = "http://graph.facebook.com/" + message["from"]["id"] + "/picture?type=small";
                                    objFacebookMessage.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss");
                                    objFacebookMessage.Id = ObjectId.GenerateNewId();
                                    objFacebookMessage.ProfileId = profile["id"].ToString();
                                    objFacebookMessage.Type = "inbox_message";
                                    objFacebookMessage.UserId = UserId;
                                    //if (!objFacebookMessageRepository.checkFacebookMessageExists(objFacebookMessage.MessageId))
                                    //{
                                        J++;
                                      //  objFacebookMessageRepository.addFacebookMessage(objFacebookMessage);
                                        MongoRepository mongorepo = new MongoRepository("FacebookMessage");
                                        mongorepo.Add<Domain.Socioboard.MongoDomain.FacebookMessage>(objFacebookMessage);
                                        logger.Error("AddFacebookMessageWithPaginationCount>>>>" + J);
                                    //}

                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
            }
        }
开发者ID:ShiftCtrlGroup,项目名称:socioboard-core,代码行数:69,代码来源:Facebook.asmx.cs

示例12: MoveInstagramCommentToMongo

        public string MoveInstagramCommentToMongo()
        {
            InstagramCommentRepository twtfeedrepo = new InstagramCommentRepository();
            string output = string.Empty;
            bool exit = true;
            int skip = 0;
            MongoRepository mongorepo = new MongoRepository("InstagramComment");

            while (exit)
            {
                List<Domain.Socioboard.Domain.InstagramComment> fbmsgs = twtfeedrepo.getAllInstagramCommentMongo(skip);
                if (fbmsgs.Count() == 0)
                {
                    exit = false;
                }

                foreach (var item in fbmsgs)
                {
                    Domain.Socioboard.MongoDomain.InstagramComment mfbmsg = new Domain.Socioboard.MongoDomain.InstagramComment();
                    mfbmsg.Id = MongoDB.Bson.ObjectId.GenerateNewId();
                    //  mfbmsg.EntryDate = item.EntryDate.ToString();
                    mfbmsg.Comment = item.Comment;
                    mfbmsg.CommentDate = item.CommentDate;
                    mfbmsg.CommentId = item.CommentId;
                    mfbmsg.FeedId = item.FeedId;
                    mfbmsg.FromName = item.FromName;
                    mfbmsg.FromProfilePic = item.FromProfilePic;
                    mfbmsg.InstagramId = item.InstagramId;
                    mfbmsg.strId = item.Id.ToString();

                    mongorepo.Add<Domain.Socioboard.MongoDomain.InstagramComment>(mfbmsg);
                }
                skip = skip + 50;
            }

            return output;
        }
开发者ID:prog-moh,项目名称:socioboard-core,代码行数:37,代码来源:FacebookAccount.asmx.cs

示例13: MoveFbMessageToMongo

        public string MoveFbMessageToMongo() 
        {
            string output = string.Empty;
            bool exit = true;
            int skip = 0;
                    MongoRepository mongorepo = new MongoRepository("FacebookMessage");

            while(exit)
            {
                List<Domain.Socioboard.Domain.FacebookMessage> fbmsgs = objFacebookMessageRepository.getAllFacebookMessagesMongo(skip);
                if (fbmsgs.Count() == 0) 
                {
                    exit = false;
                }

                foreach (var item in fbmsgs)
                {
                    Domain.Socioboard.MongoDomain.FacebookMessage mfbmsg = new Domain.Socioboard.MongoDomain.FacebookMessage();
                    mfbmsg.Id = MongoDB.Bson.ObjectId.GenerateNewId();
                    mfbmsg.EntryDate = item.EntryDate.ToString("yyyy/MM/dd HH:mm:ss");
                    mfbmsg.FbComment = item.FbComment;
                    mfbmsg.FbLike = item.FbLike;
                    mfbmsg.FromId = item.FromId;
                    mfbmsg.FromName = item.FromName;
                    mfbmsg.FromProfileUrl = item.FromProfileUrl;
                    mfbmsg.IsArchived = item.IsArchived.ToString();
                    mfbmsg.Message = item.Message;
                    mfbmsg.MessageDate = item.MessageDate.ToString("yyyy/MM/dd HH:mm:ss");
                    mfbmsg.MessageId = item.MessageId;
                    mfbmsg.Picture = item.Picture;
                    mfbmsg.ProfileId = item.ProfileId;
                    mfbmsg.Type = item.Type;
                    mfbmsg.UserId = item.UserId.ToString();
                    mongorepo.Add<Domain.Socioboard.MongoDomain.FacebookMessage>(mfbmsg);
                }
                skip = skip + 50;
            }
          
            return output;
        }
开发者ID:prog-moh,项目名称:socioboard-core,代码行数:40,代码来源:FacebookAccount.asmx.cs

示例14: BatchTest

        public void BatchTest()
        {
            IRepository<Customer> _customerRepo = new MongoRepository<Customer>();

            var custlist = new List<Customer>(new Customer[] {
                new Customer() { FirstName = "Customer A" },
                new Customer() { FirstName = "Client B" },
                new Customer() { FirstName = "Customer C" },
                new Customer() { FirstName = "Client D" },
                new Customer() { FirstName = "Customer E" },
                new Customer() { FirstName = "Client F" },
                new Customer() { FirstName = "Customer G" },
            });

            //Insert batch
            _customerRepo.Add(custlist);

            var count = _customerRepo.Count();
            Assert.AreEqual(7, count);
            foreach (Customer c in custlist)
                Assert.AreNotEqual(new string('0', 24), c.Id);

            //Update batch
            foreach (Customer c in custlist)
                c.LastName = c.FirstName;
            _customerRepo.Update(custlist);

            foreach (Customer c in _customerRepo)
                Assert.AreEqual(c.FirstName, c.LastName);

            //Delete by criteria
            _customerRepo.Delete(f => f.FirstName.StartsWith("Client"));

            count = _customerRepo.Count();
            Assert.AreEqual(4, count);

            //Delete specific object
            _customerRepo.Delete(custlist[0]);

            //Test AsQueryable
            var selectedcustomers = from cust in _customerRepo
                                    where cust.LastName.EndsWith("C") || cust.LastName.EndsWith("G")
                                    select cust;

            Assert.AreEqual(2, selectedcustomers.ToList().Count);

            count = _customerRepo.Count();
            Assert.AreEqual(3, count);

            //Drop entire repo
            new MongoRepositoryManager<Customer>().Drop();

            count = _customerRepo.Count();
            Assert.AreEqual(0, count);
        }
开发者ID:rodolfofadino,项目名称:MongoRepository-Fork,代码行数:55,代码来源:RepoTests.cs

示例15: CustomIDTypeTest

        public void CustomIDTypeTest()
        {
            var xint = new MongoRepository<IntCustomer, int>();
            xint.Add(new IntCustomer() { Id = 1, Name = "Test A" });
            xint.Add(new IntCustomer() { Id = 2, Name = "Test B" });

            var yint = xint.GetById(2);
            Assert.AreEqual(yint.Name, "Test B");

            xint.Delete(2);
            Assert.AreEqual(1, xint.Count());
        }
开发者ID:rodolfofadino,项目名称:MongoRepository-Fork,代码行数:12,代码来源:RepoTests.cs


注:本文中的MongoRepository.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。