當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.MongoDBRef類代碼示例

本文整理匯總了C#中MongoDB.Driver.MongoDBRef的典型用法代碼示例。如果您正苦於以下問題:C# MongoDBRef類的具體用法?C# MongoDBRef怎麽用?C# MongoDBRef使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MongoDBRef類屬於MongoDB.Driver命名空間,在下文中一共展示了MongoDBRef類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AttachPackage

        //public StandardResult ParserHolders(string[] holderAccounts)
        //{
        //    if (holderAccounts == null || holderAccounts.Length == 0) return Result(iTripExceptionCode.Error_Null_Reference);
        //    var resp = GetRespository<Holder>();
        //    var holders = resp.Select(h => holderAccounts.Contains(h.Account)).ToList();
        //    if (holders.Count == holderAccounts.Length)
        //        return Result(holders);
        //    List<Holder> hs = new List<Holder>();
        //    holderAccounts.ForEach(delegate(string acc)
        //    {
        //        if (!holders.Any(h => h.Account == acc))
        //            hs.Add(new Holder(acc));
        //    });
        //    resp.Insert(hs);
        //    hs.AddRange(holders);
        //    return Result(hs);
        //}
        public int AttachPackage(string[] holders, MongoDBRef package)
        {
            if (holders == null || holders.Length == 0) return 0;
            List<PackageHolding> phs = new List<PackageHolding>();

            holders.ForEach(a => phs.Add(new PackageHolding(a, package.Id.AsString)));
            GetRespository<PackageHolding>().Insert(phs);
            return phs.Count;
        }
開發者ID:WinHuStudio,項目名稱:iTrip,代碼行數:26,代碼來源:HolderResolver.cs

示例2: TestDeserializeMongoDBRef

        public void TestDeserializeMongoDBRef() {
            var dbRef = new MongoDBRef("test", ObjectId.GenerateNewId());
            var c = new C { DbRef = dbRef };
            collection.RemoveAll();
            collection.Insert(c);

            var rehydrated = collection.FindOne();
            Assert.IsNull(rehydrated.DbRef.DatabaseName);
            Assert.AreEqual(dbRef.CollectionName, rehydrated.DbRef.CollectionName);
            Assert.AreEqual(dbRef.Id, rehydrated.DbRef.Id);
        }
開發者ID:jenrom,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:CSharp134Tests.cs

示例3: ModifyContent

        public ActionResult ModifyContent(string formId, string fieldId,ContentAction contentAction)
        {
            if(formsCollection != null && !string.IsNullOrEmpty(formId) && !string.IsNullOrEmpty(fieldId))
            {
                Form form = GetForm(formId);
                if(form != null)
                {
                    if(DBHelper.GetInstance().GetField(fieldId) != null)
                    {
                        MongoDBRef dbref = new MongoDBRef(DBHelper.GetInstance().FieldsCollection().Name,fieldId);

                        if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction))
                        {
                            if(form.Contents.Contains(dbref))
                            {
                                if(contentAction == ContentAction.Remove)
                                {
                                    form.Contents.Remove(dbref);
                                }
                                else if(contentAction == ContentAction.Up)
                                {
                                    LinkedListNode<MongoDBRef> prev = form.Contents.Find(dbref).Previous;
                                    if(prev != null)
                                    {
                                        form.Contents.Remove(dbref);
                                        form.Contents.AddBefore(prev,dbref);
                                    }
                                }
                                else if(contentAction == ContentAction.Down)
                                {
                                    LinkedListNode<MongoDBRef> next = form.Contents.Find(dbref).Next;
                                    if(next != null)
                                    {
                                        form.Contents.Remove(dbref);
                                        form.Contents.AddAfter(next,dbref);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if(!form.Contents.Contains(dbref))
                            {
                                form.Contents.AddLast(dbref);
                            }
                        }

                        formsCollection.Save(form);
                    }
                }
            }
            return RedirectToAction("Index",new{Id = formId});
        }
開發者ID:jimmy00784,項目名稱:BusinessFlowManager,代碼行數:53,代碼來源:FormController.cs

示例4: DBClient

 public DBClient(MongoUrl url, MongoDBRef dbRef)
 {
     if (url == null)
         throw new MongoAuthenticationException("Wrong MongoUrl");
     if (dbRef == null)
         throw new MongoAuthenticationException("Wrong Collection Value");
     _dbName = dbRef.DatabaseName;
     _collectionName = dbRef.CollectionName;
     //this._type = type;
     MongoClientSettings setting = MongoClientSettings.FromUrl(url);
     _client = new MongoClient(url);
 }
開發者ID:season179,項目名稱:MongoDB.Repository,代碼行數:12,代碼來源:DBClient.cs

示例5: TestDateTimeRefId

        public void TestDateTimeRefId() {
            var id = ObjectId.GenerateNewId();
            var dateTime = BsonConstants.UnixEpoch; ;
            var dbRef = new MongoDBRef("collection", dateTime);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : ISODate('1970-01-01T00:00:00Z') } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
開發者ID:simi--,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:MongoDBRefTests.cs

示例6: TestDocumentRefId

        public void TestDocumentRefId() {
            var id = ObjectId.GenerateNewId();
            var refId = new BsonDocument { { "x", 1 }, { "y", 2 } };
            var dbRef = new MongoDBRef("collection", refId);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : { 'x' : 1, 'y' : 2 } } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
開發者ID:simi--,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:MongoDBRefTests.cs

示例7: TestGuidRefId

        public void TestGuidRefId()
        {
            var id = ObjectId.GenerateNewId();
            var guid = Guid.NewGuid();
            var dbRef = new MongoDBRef("collection", guid);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : CSUUID('#guid') } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("#guid", guid.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
開發者ID:kamaradclimber,項目名稱:mongo-csharp-driver,代碼行數:17,代碼來源:MongoDBRefTests.cs

示例8: TestFetchDBRef

        public void TestFetchDBRef() {
            var collectionName = "testdbref";
            var collection = database.GetCollection(collectionName);
            var document = new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "P", "x" } };
            collection.Insert(document);

            var dbRef = new MongoDBRef(collectionName, document["_id"].AsObjectId);
            var fetched = database.FetchDBRef(dbRef);
            Assert.AreEqual(document, fetched);
            Assert.AreEqual(document.ToJson(), fetched.ToJson());

            var dbRefWithDatabaseName = new MongoDBRef(database.Name, collectionName, document["_id"].AsObjectId);
            fetched = server.FetchDBRef(dbRefWithDatabaseName);
            Assert.AreEqual(document, fetched);
            Assert.AreEqual(document.ToJson(), fetched.ToJson());
            Assert.Throws<ArgumentException>(() => { server.FetchDBRef(dbRef); });
        }
開發者ID:ebix,項目名稱:mongo-csharp-driver,代碼行數:17,代碼來源:MongoDatabaseTests.cs

示例9: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server = MongoServer.Create(connectionString);
            var db = server.GetDatabase("Zalagaonica");
            byte[] slika_ugovora = File.ReadAllBytes(textBox1.Text);
            UgovorClass ugovor = new UgovorClass
            {
                datumPotpisivanja = dateTimePicker1.Value.ToString(),
                datumIsteka = dateTimePicker2.Value.ToString(),
                datNovac = Int32.Parse(textBox3.Text),
                slikaUgovora = slika_ugovora
            };
            var collection = db.GetCollection<UgovorClass>("ugovori");
            collection.Insert(ugovor);
            ovajUgovor = new MongoDBRef("ugovori",ugovor.Id);

            //var nc = db.GetCollection<UgovorClass>("ugovori");
            //foreach (UgovorClass item in nc.FindAll())
            //{
            //     MessageBox.Show(item.datumIsteka);
            //}
        }
開發者ID:ivica94,項目名稱:Zalagaonica,代碼行數:23,代碼來源:Ugovor.cs

示例10: MappingAuthor

        static async Task  MappingAuthor()
        {
            var client = new MongoClient("mongodb://rpt:[email protected]:27017/forums");

            var forums = client.GetDatabase("forums");

            var users = forums.GetCollection<BsonDocument>("users");

            var threads = forums.GetCollection<BsonDocument>("uwp_threads");

            var updates = new List<WriteModel<BsonDocument>>();

            await threads.Find(new BsonDocument())
                .ForEachAsync(async (thread) => {
                    var filter = Builders<BsonDocument>.Filter.Eq("id", thread.GetElement("authorId").Value);

                    var author = await users.Find(filter).FirstOrDefaultAsync();

                    var dbref = new MongoDBRef("users", author.GetElement("_id").Value.AsObjectId);
                   
                    updates.Add(new UpdateOneModel<BsonDocument>(new BsonDocument("_id", thread.GetElement("_id").Value), new BsonDocument("$set", new BsonDocument("author", dbref.ToBsonDocument()))));
                });

            await threads.BulkWriteAsync(updates);
        }
開發者ID:Myfreedom614,項目名稱:toolkit,代碼行數:25,代碼來源:Program.cs

示例11: DealPackage

 public int DealPackage(MongoDBRef package, string[] holders)
 {
     IHolderResolver holderResolver = new HolderResolver();
     return holderResolver.AttachPackage(holders, package);
 }
開發者ID:WinHuStudio,項目名稱:iTrip,代碼行數:5,代碼來源:PackageDealer.cs

示例12: UnlinkContact

 /// <summary>
 /// Unlinks a contact
 /// </summary>
 /// <param name="link"></param>
 private void UnlinkContact(MongoDBRef link)
 {
     this.LinkedContacts.Remove(link);
     Save();
 }
開發者ID:SleeplessByte,項目名稱:life-insights,代碼行數:9,代碼來源:Contact.cs

示例13: InsertPat

        public string InsertPat(mPatInfo pat, string User)
        {
            MongoServer server = ConnectDB();
             var db = server.GetDatabase("hdb");
             string pid = "";
            try
            {
                using (server.RequestStart(db))
                {

                    var Usercollection = db.GetCollection<mUser>("Users");

                    var query = new QueryDocument("UserName", User);
                    //mUser u = new mUser();
                    //u.UserName = "123";
                    //u.PassWord = "123";
                    mUser entity = Usercollection.FindOne(query);
                    MongoDBRef r = new MongoDBRef("Users", entity.Id);

                    var PatCollection = db.GetCollection<mPatInfo>("Pats");
                    pat.Doctor = r;
                    PatCollection.Insert(pat);
                    pid = pat.PatId.ToString();
                    //collection.Remove(query);

                }
                return pid;
            }
            catch (System.Exception ex)
            {
                return pid;
            }
        }
開發者ID:JaneBlue,項目名稱:Website,代碼行數:33,代碼來源:VisitDataOperation.cs

示例14: TestInt64RefId

        public void TestInt64RefId()
        {
            var id = ObjectId.GenerateNewId();
            var dbRef = new MongoDBRef("collection", 123456789012345L);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : NumberLong('123456789012345') } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
開發者ID:RavenZZ,項目名稱:MDRelation,代碼行數:15,代碼來源:MongoDBRefTests.cs

示例15: SocetProducts

 public SocetProducts(string productId, string warehouseSocetId)
 {
     WarehouseSocetId = new MongoDBRef("WarehouseSocet", warehouseSocetId);
     ProductId = new MongoDBRef("Product", productId);
     this.TimeStamp = DateTime.Now;
 }
開發者ID:Drazel,項目名稱:Warehouse,代碼行數:6,代碼來源:SocetProducts.cs


注:本文中的MongoDB.Driver.MongoDBRef類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。