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


C# ODatabase.JavaScript方法代码示例

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


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

示例1: ShouldExecuteSimpleJavascriptQuery

        public void ShouldExecuteSimpleJavascriptQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                OVertex vertex1 = database
                    .Create.Vertex<OVertex>()
                    .Set("Foo", "foo string value 1")
                    .Set("Bar", 12345)
                    .Run();

                OVertex vertex2 = database
                    .Create.Vertex<OVertex>()
                    .Set("Foo", "foo string value 2")
                    .Set("Bar", 54321)
                    .Run();

                OEdge edge1 = database
                    .Create.Edge<OEdge>()
                    .From(vertex1)
                    .To(vertex2)
                    .Set("Foo", "foo string value 3")
                    .Set("Bar", 123)
                    .Run();

                List<ODocument> documents = database
                    .JavaScript("db.command('select from V');")
                    .Run()
                    .ToList();

                Assert.AreEqual(2, documents.Count);
                var loadedVertex1 = documents.Find(d => d.ORID.Equals(vertex1.ORID));
                var loadedVertex2 = documents.Find(d => d.ORID.Equals(vertex2.ORID));
                Assert.IsNotNull(loadedVertex1);
                Assert.IsNotNull(loadedVertex2);

                Assert.AreEqual(vertex1.GetField<string>("Foo"), loadedVertex1.GetField<string>("Foo"));
                Assert.AreEqual(vertex1.GetField<int>("Bar"), loadedVertex1.GetField<int>("Bar"));
                Assert.AreEqual(vertex2.GetField<string>("Foo"), loadedVertex2.GetField<string>("Foo"));
                Assert.AreEqual(vertex2.GetField<int>("Bar"), loadedVertex2.GetField<int>("Bar"));

                Assert.AreEqual(1, loadedVertex1.GetField<HashSet<ORID>>("out_").Count);
                Assert.IsTrue(loadedVertex1.GetField<HashSet<ORID>>("out_").Contains(edge1.ORID));
                Assert.IsTrue(loadedVertex2.GetField<HashSet<ORID>>("in_").Contains(edge1.ORID));
            }
        }
开发者ID:emman-ok,项目名称:OrientDB-NET.binary,代码行数:46,代码来源:JavascriptTest.cs

示例2: ShouldExecuteSimpleFunction

 public void ShouldExecuteSimpleFunction()
 {
     using (TestDatabaseContext testContext = new TestDatabaseContext())
     using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
     {
         database
             .Command("create function sum 'return parseInt(a)+parseInt(b);' parameters [a , b] language javascript");
         var result = database
             .JavaScript("sum(a,b);")
             .Set("a",3)
             .Set("b",5)
             .Run()
             .ToSingle();
         
         Assert.IsNotNull(result);
         Assert.AreEqual(1, result.Count);
         var actual = result.GetField<string>("value");
         if (actual != "8") // 8 seems to come back from this call - maybe depends on exact version of OrientDB server?... Anyway, it's a good enough result
         {
             Assert.AreEqual("8.0d", actual);
         }
     }
 }
开发者ID:emman-ok,项目名称:OrientDB-NET.binary,代码行数:23,代码来源:JavascriptTest.cs


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