本文整理汇总了C#中MongoDB.Driver.MongoDBRef类的典型用法代码示例。如果您正苦于以下问题:C# MongoDBRef类的具体用法?C# MongoDBRef怎么用?C# MongoDBRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoDBRef类属于MongoDB.Driver命名空间,在下文中一共展示了MongoDBRef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: ModifyContent
public ActionResult ModifyContent(string flowId, string groupId, string taskId, ContentAction contentAction)
{
if(flowsCollection != null && !string.IsNullOrEmpty(flowId) && !string.IsNullOrEmpty(groupId) && !string.IsNullOrEmpty(taskId))
{
Flow flow = GetFlow(flowId);
if(flow != null)
{
Group group = DBHelper.GetInstance().GetGroup(groupId);
Task task = DBHelper.GetInstance().GetTask(taskId);
if(group != null && task != null)
{
MongoDBRef groupdbref = new MongoDBRef(DBHelper.GetInstance().GroupsCollection().Name,group.Name);
MongoDBRef taskdbref = new MongoDBRef(DBHelper.GetInstance().TasksCollection().Name,task.Name);
FlowContentRef dbref = new FlowContentRef{Group = groupdbref, Task = taskdbref};
if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction))
{
bool found = false;
foreach(FlowContentRef fcref in flow.Contents)
{
if(fcref.Equals(dbref))
{
dbref = fcref;
found = true;
break;
}
}
if(found)
{
if(contentAction == ContentAction.Remove)
{
flow.Contents.Remove(dbref);
}
else if(contentAction == ContentAction.Up)
{
LinkedListNode<FlowContentRef> prev = flow.Contents.Find(dbref).Previous;
if(prev != null)
{
flow.Contents.Remove(dbref);
flow.Contents.AddBefore(prev,dbref);
}
}
else if(contentAction == ContentAction.Down)
{
LinkedListNode<FlowContentRef> next = flow.Contents.Find(dbref).Next;
if(next != null)
{
flow.Contents.Remove(dbref);
flow.Contents.AddAfter(next,dbref);
}
}
}
}
else
{
if(!flow.Contents.Contains(dbref))
{
flow.Contents.AddLast(dbref);
}
}
flowsCollection.Save(flow);
}
}
}
return RedirectToAction("Index",new{Id = flowId});
}
开发者ID:jimmy00784,项目名称:BusinessFlowManager,代码行数:67,代码来源:FlowController.cs
示例17: SaveNextState
public ActionResult SaveNextState(string flowId, string stateId, string route, string nextStateId, string nextTaskId)
{
if(flowsCollection != null && flowStatesCollection != null
&& !string.IsNullOrEmpty(flowId) && !string.IsNullOrEmpty(stateId)
&& !string.IsNullOrEmpty(route) && !string.IsNullOrEmpty(nextStateId)
&& !string.IsNullOrEmpty(nextTaskId))
{
Flow flow = GetFlow(flowId);
FlowState state = GetFlowState(stateId);
FlowState nextState = SaveFlowState(flowId,nextStateId,nextTaskId);
if(state.NextStates == null)
{
state.NextStates = new Dictionary<string,MongoDBRef>();
}
if(nextState != null)
{
MongoDBRef stateRef = new MongoDBRef(flowStatesCollection.Name,nextState.State);
if(!state.NextStates.Keys.Contains(route))
{
state.NextStates.Add(route, stateRef);
}
else
{
state.NextStates[route] = stateRef;
}
flowStatesCollection.Save(state);
}
}
return RedirectToAction("Index");
}
开发者ID:jimmy00784,项目名称:BusinessFlowManager,代码行数:30,代码来源:FlowController.cs
示例18: TestEqualsWithDatabase
public void TestEqualsWithDatabase()
{
var a1 = new MongoDBRef("d", "c", 1);
var a2 = new MongoDBRef("d", "c", 1);
var a3 = a2;
var b = new MongoDBRef("x", "c", 1);
var c = new MongoDBRef("d", "x", 1);
var d = new MongoDBRef("d", "c", 2);
var null1 = (MongoDBRef)null;
var null2 = (MongoDBRef)null;
Assert.AreNotSame(a1, a2);
Assert.AreSame(a2, a3);
Assert.IsTrue(a1.Equals((object)a2));
Assert.IsFalse(a1.Equals((object)null));
Assert.IsFalse(a1.Equals((object)"x"));
Assert.IsTrue(a1 == a2);
Assert.IsTrue(a2 == a3);
Assert.IsFalse(a1 == b);
Assert.IsFalse(a1 == c);
Assert.IsFalse(a1 == d);
Assert.IsFalse(a1 == null1);
Assert.IsFalse(null1 == a1);
Assert.IsTrue(null1 == null2);
Assert.IsFalse(a1 != a2);
Assert.IsFalse(a2 != a3);
Assert.IsTrue(a1 != b);
Assert.IsTrue(a1 != c);
Assert.IsTrue(a1 != d);
Assert.IsTrue(a1 != null1);
Assert.IsTrue(null1 != a1);
Assert.IsFalse(null1 != null2);
Assert.AreEqual(a1.GetHashCode(), a2.GetHashCode());
}
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:37,代码来源:MongoDBRefTests.cs
示例19: SaveRecord
//public static void InsertSort(List<mPatInfo> data)
//{
// var count = data.Count;
// for (int i = 1; i < count; i++)
// {
// var t = data[i].VisitRecord.Last().VisitDate;
// var d = data[i];
// var j = i;
// while (j > 0 && data[j - 1].VisitRecord.Last().VisitDate < t)
// {
// data[j] = data[j - 1];
// --j;
// }
// data[j] = d;
// }
//}
public bool SaveRecord(string PatID, mVisitData VData)
{
try
{
MongoServer server = ConnectDB();
var db = server.GetDatabase("hdb");
mVisitData vdata = DataPreprocess(VData);
using (server.RequestStart(db))
{
var collection = db.GetCollection<mPatInfo>("Pats");
ObjectId id = new ObjectId(PatID);
// Create a document with the ID we want to find
var query = new QueryDocument { { "_id", id } };
mPatInfo entity = collection.FindOne(query);
var Visitcollection = db.GetCollection<mVisitRecord>("VisitRecords");
mVisitRecord vr = vdata.Visitrecord;
vr.VisitDate = DateTime.Now.Date;
Visitcollection.Insert(vr);
MongoDBRef r = new MongoDBRef("VisitRecords", vr.VisitrecordId);
entity.refs.Add(r);
mRelatedInfo mr = vdata.RelateInfo;
entity.relatedInfo = mr;
collection.Save(entity);
}
return true;
}
catch (Exception e)
{
return false;
}
}
开发者ID:JaneBlue,项目名称:Website,代码行数:51,代码来源:VisitDataOperation.cs
示例20: TestWithDatabase
public void TestWithDatabase() {
var id = ObjectId.GenerateNewId();
var dbRef = new MongoDBRef("database", "collection", ObjectId.GenerateNewId());
var obj = new C { Id = id, DBRef = dbRef };
var json = obj.ToJson();
var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : ObjectId('#ref'), '$db' : 'database' } }";
expected = expected.Replace("#id", id.ToString());
expected = expected.Replace("#ref", dbRef.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
注:本文中的MongoDB.Driver.MongoDBRef类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论