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


C# JObject.SetKey方法代码示例

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


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

示例1: Create

		public void Create()
		{
			var doc = new JObject
			{
				{ "Name", "ZEK" },
				{ "Capacity", 999 }
			};

			doc.SetKey("ZEK");

			var created = Database.Document.Create(doc, "Station", true);

			created.AssertRevision();
		}
开发者ID:bbqchickenrobot,项目名称:ArangoDB.Api,代码行数:14,代码来源:DocumentTestCase.cs

示例2: Update

		public void Update()
		{
			Create();

			var doc = new JObject
			{
				{ "Name", "ZEK" },
				{ "Capacity", 523 }
			};

			doc.SetKey("ZEK");

			var updated = Database.Document.Update("Station/ZEK", doc);

			updated.AssertSuccess();
		}
开发者ID:bbqchickenrobot,项目名称:ArangoDB.Api,代码行数:16,代码来源:DocumentTestCase.cs

示例3: Create

		public void Create()
		{
			var station = new JObject
			{
				{"Name", "SOC"},
				{"Capacity", 200}
			};

			station.SetKey("SOC");

			var line1 = new JObject
			{
				{"Name", "SOC1"},
				{"MainLine", true}
			};

			line1.SetKey("SOC1");

			var line2 = new JObject
			{
				{"Name", "SOC2"},
				{"MainLine", false}
			};

			line2.SetKey("SOC2");

			var stationCreated = Database.Document.Create(station, "Station", true);
			var line1Created = Database.Document.Create(line1, "Line", true);
			var line2Created = Database.Document.Create(line2, "Line", true);

			var collectionCreated = Database.Collection.Create("Station-Line", CollectionType.Edge);

			var stationLine1EdgeCreated = Database.Edge.Create("Station-Line", "Station/SOC", "Line/SOC1", "SOC-SOC1");

			var stationLine2EdgeCreated = Database.Edge.Create("Station-Line", "Station/SOC", "Line/SOC2", "SOC-SOC2");

			stationCreated.AssertRevision();
			line1Created.AssertRevision();
			line2Created.AssertRevision();
			collectionCreated.AssertSuccess();
			stationLine1EdgeCreated.AssertRevision();
			stationLine2EdgeCreated.AssertRevision();
		}
开发者ID:bbqchickenrobot,项目名称:ArangoDB.Api,代码行数:43,代码来源:EdgeTestCase.cs

示例4: SimpleUsage

		public void SimpleUsage()
		{
			using (var client = new ArangoClient())
			{
				// Init the client, is possible to define settings like host/port
				client.Init();

				// Create new database
				client.Database.Create("ApiTests");

				// Scope to the recently created database
				using (var db = client.UseDatabase("ApiTests"))
				{
					// Create Station document collection
					db.Collection.Create("Station");

					// Create a station with key ZEK
					var stationZEK = new JObject
					{
						{ "_key", "ZEK" },
						{ "Name", "ZEK" },
						{ "Capacity", 2 }
					};

					// All operations return ArangoResponse generic type
					ArangoResponse<JObject> createResult = db.Document.Create(stationZEK, "Station");

					// By default, this API doesn't throws a Exception if an operation fail, 
					// always is good check the Status.Error property. 
					// This behavior can be configured in ArangoClientSettings.ThrowExceptions
					if (createResult.Status.Error)
					{
						throw new Exception(createResult.Status.ErrorMessage);
					}

					// Or just call the ThrowIfError() method
					createResult.ThrowIfError();

					// Status has other details
					// https://www.arangodb.org/manuals/current/ImplementorManualArangoErrors.html
					int errorNum = createResult.Status.ErrorNum;
					int code = createResult.Status.Code;
					HttpStatusCode httpStatusCode = createResult.Status.StatusCode;
					TimeSpan totalDuration = createResult.Status.TotalDuration;
					TimeSpan serverDuration = createResult.Status.ServerDuration;

					// Each operation have a type of result
					JObject resultOfOperation = createResult.Result;

					// Create the main line of ZEK station
					var lineZEK1 = new JObject
					{
						{"Name", "ZEK1"},
						{"MainLine", true}
					};

					// Is possible to use the SetKey extension method to set the _key
					lineZEK1.SetKey("ZEK1");

					// Are possible to create collections on the fly
					db.Document.Create(lineZEK1, "Line", createCollection: true);

					// Now, we create the edge collection to link Station with Lines
					db.Collection.Create("Station-Line", CollectionType.Edge);

					// Create the edge to link ZEK station with ZEK1 line
					db.Edge.Create("Station-Line", "Station/ZEK", "Line/ZEK1", "ZEK-ZEK1");
				}

				// To finalize the test, drop the database
				client.Database.Drop("ApiTests");
			}
		}
开发者ID:bbqchickenrobot,项目名称:ArangoDB.Api,代码行数:73,代码来源:UsageTestCase.cs


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