当前位置: 首页>>代码示例>>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;未经允许,请勿转载。