本文整理汇总了C#中ODatabase.Command方法的典型用法代码示例。如果您正苦于以下问题:C# ODatabase.Command方法的具体用法?C# ODatabase.Command怎么用?C# ODatabase.Command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODatabase
的用法示例。
在下文中一共展示了ODatabase.Command方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProblemDeseralizingObjectWithDateTimeFields_31
public void ProblemDeseralizingObjectWithDateTimeFields_31()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
var startRecords = database.CountRecords;
// explicitly setting the timezone to UTC instead of the JVM default timezone
// FIXME: this is a work around for now
database.Command("ALTER DATABASE TIMEZONE UTC");
database.Create.Class<File>().Extends<OVertex>().CreateProperties().Run();
var dateTime = DateTime.UtcNow;
// OrientDB truncates milliseconds, so do so here for a proper comparison
dateTime = dateTime.AddTicks( - (dateTime.Ticks % TimeSpan.TicksPerSecond));
database.Insert(new File
{
Filename = "myfile",
Created = dateTime
}).Run();
var doc = database.Select().From<File>().ToList().First();
var file = doc.To<File>();
// FIXME: the time zone is off
Assert.That(file.Created, Is.EqualTo(dateTime));
var endRecords = database.CountRecords;
Assert.AreEqual(startRecords + 1, endRecords);
}
}
示例2: TestOrderedEdges
public void TestOrderedEdges()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
database.Create.Class<Widget>().Extends("V").CreateProperties().Run();
database.Create.Class<WidgetVersion>().Extends("V").CreateProperties().Run();
database.Create.Class("VersionOf").Extends("E").Run();
database.Command(string.Format("create property {0}.out link {1}", "VersionOf", typeof(WidgetVersion).Name));
database.Command(string.Format("create property {0}.in link {1}", "VersionOf", typeof(Widget).Name));
database.Command(string.Format("create property {1}.in_{0} ANY", "VersionOf", typeof(Widget).Name));
database.Command(string.Format("alter property {1}.in_{0} custom ordered=true", "VersionOf", typeof(Widget).Name));
var w1 = new Widget() {Value = 12};
var wv1 = new WidgetVersion() {Value = 23};
var wv2 = new WidgetVersion() { Value = 34 };
var v1 = database.Create.Vertex(w1).Run();
var v2 = database.Create.Vertex(wv1).Run();
var v3 = database.Create.Vertex(wv2).Run();
database.Create.Edge("VersionOf").From(v1).To(v2).Run();
database.Create.Edge("VersionOf").From(v1).To(v3).Run();
var loaded1 = database.Load.ORID(v1.ORID).Run();
var typed1 = loaded1.To<Widget>();
Assert.AreEqual(2, typed1.out_VersionOf.Count);
Assert.AreEqual(12, typed1.Value);
var loaded2 = database.Load.ORID(v2.ORID).Run();
var typed2 = loaded2.To<WidgetVersion>();
Assert.AreNotEqual(null, typed2.in_VersionOf);
}
}
}
示例3: TestOrderedEdges
public void TestOrderedEdges()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
database.Command("alter database custom useLightweightEdges=false");
database.Create.Class<Widget>().Extends("V").CreateProperties().Run();
database.Create.Class<WidgetVersion>().Extends("V").CreateProperties().Run();
database.Create.Class("VersionOf").Extends("E").Run();
var w1 = new Widget() { Value = 12 };
var wv1 = new WidgetVersion() { Value = 23 };
var wv2 = new WidgetVersion() { Value = 34 };
var v1 = database.Create.Vertex(w1).Run();
var v2 = database.Create.Vertex(wv1).Run();
var v3 = database.Create.Vertex(wv2).Run();
var e1 = database.Create.Edge("VersionOf").From(v1).To(v2).Run();
var e2 = database.Create.Edge("VersionOf").From(v1).To(v3).Run();
var loaded1 = database.Load.ORID(v1.ORID).Run<Widget>();
Assert.Equal(2, loaded1.out_VersionOf.Count);
Assert.True(loaded1.out_VersionOf.Contains(e1.ORID));
Assert.True(loaded1.out_VersionOf.Contains(e2.ORID));
Assert.Equal(12, loaded1.Value);
var loaded2 = database.Load.ORID(v2.ORID).Run<WidgetVersion>();
Assert.NotNull(loaded2.in_VersionOf);
Assert.Equal(1, loaded2.in_VersionOf.Count);
Assert.Equal(23, loaded2.Value);
Assert.True(loaded2.in_VersionOf.Contains(e1.ORID));
var loaded3 = database.Load.ORID(v3.ORID).Run<WidgetVersion>();
Assert.NotNull(loaded3.in_VersionOf);
Assert.Equal(1, loaded3.in_VersionOf.Count);
Assert.Equal(34, loaded3.Value);
Assert.True(loaded3.in_VersionOf.Contains(e2.ORID));
}
}
示例4: ShouldCreateRecordContainingSingleQuote
public void ShouldCreateRecordContainingSingleQuote()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
using (var db = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
if (!db.Schema.IsClassExist<TestClass>())
{
db.Create.Class<TestClass>().CreateProperties<TestClass>().Run();
}
db.Command("delete from TestClass");
var text = @"Jim'n";
var test = new TestClass() { SomeString = text };
db.Insert(test).Run();
var result = db.Select().From<TestClass>().ToList<TestClass>();
Assert.Equal(text, result.Single().SomeString);
}
}
示例5: ShouldCreateEdgeClusterFromTo
public void ShouldCreateEdgeClusterFromTo()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestEdgeClass")
.Extends<OEdge>()
.Run();
database
.Create.Cluster("TestCluster", OClusterType.Physical)
.Run();
var res = database.Command("alter class TestEdgeClass addcluster testcluster");
OVertex vertex1 = database
.Create.Vertex<OVertex>()
.Run();
OVertex vertex2 = database
.Create.Vertex<OVertex>()
.Run();
OEdge createdEdge = database
.Create.Edge("TestEdgeClass")
.Cluster("TestCluster")
.From(vertex1.ORID)
.To(vertex2.ORID)
.Run();
Assert.NotNull(createdEdge.ORID);
Assert.Equal("TestEdgeClass", createdEdge.Label);
Assert.Equal("TestEdgeClass", createdEdge.OClassName);
Assert.Equal(vertex2.ORID, createdEdge.InV);
Assert.Equal(vertex1.ORID, createdEdge.OutV);
}
}
}
示例6: 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);
}
}
}
示例7: ShouldFetchDocumentsConnectedByEdges
public void ShouldFetchDocumentsConnectedByEdges()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// Need to set this
database.Command("alter database custom useLightweightEdges=true");
database.Create.Class("House").Extends("V").Run();
database.Create.Class("Person").Extends("V").Run();
database.Create.Class("Owns").Extends("E").Run();
var house = new ODocument { OClassName = "House" };
database.Create.Vertex(house).Run();
var person = new ODocument { OClassName = "Person" };
person.SetField("name", "Shawn");
database.Create.Vertex(person).Run();
var person1 = new ODocument { OClassName = "Person" };
person1.SetField("name", "Roman");
database.Create.Vertex(person1).Run();
database.Create.Edge("Owns").From(person).To(house).Run();
database.Create.Edge("Owns").From(person1).To(house).Run();
house = database.Query("select from House", "*:-1").FirstOrDefault();
Assert.That(house != null);
Assert.That(database.ClientCache.Count(), Is.EqualTo(2), "client cache should contain two records");
}
}
}
示例8: ShouldInsertIntoClusterSet
public void ShouldInsertIntoClusterSet()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
database
.Create.Cluster("TestCluster", OClusterType.Physical)
.Run();
database.Command("alter class TestClass addcluster TestCluster");
ODocument insertedDocument = database
.Insert()
.Into("TestClass")
.Cluster("TestCluster")
.Set("foo", "foo string value")
.Set("bar", 12345)
.Run();
Assert.IsTrue(insertedDocument.ORID != null);
Assert.AreEqual(insertedDocument.OClassName, "TestClass");
Assert.AreEqual(insertedDocument.GetField<string>("foo"), "foo string value");
Assert.AreEqual(insertedDocument.GetField<int>("bar"), 12345);
}
}
}
示例9: ShouldUpdateCluster
public void ShouldUpdateCluster()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
database
.Create.Cluster("TestCluster", OClusterType.Physical)
.Run();
database.Command("alter class TestClass addcluster TestCluster");
ODocument document = new ODocument();
document.OClassName = "TestClass";
document
.SetField("foo", "foo string value")
.SetField("bar", 12345);
database
.Insert(document)
.Cluster("TestCluster")
.Run();
database
.Insert(document)
.Cluster("TestCluster")
.Run();
document
.SetField("bar", 54321)
.SetField("baz", "new baz value");
int documentsUpdated = database
.Update(document)
.Cluster("TestCluster")
.Run();
Assert.AreEqual(documentsUpdated, 2);
List<ODocument> documents = database
.Select()
.From("cluster:TestCluster")
.ToList();
Assert.AreEqual(documents.Count, 2);
for (int i = 0; i < documents.Count; i++)
{
Assert.IsTrue(documents[i].ORID != null);
Assert.AreEqual(documents[i].OClassName, document.OClassName);
Assert.AreEqual(documents[i].GetField<string>("foo"), document.GetField<string>("foo"));
Assert.AreEqual(documents[i].GetField<int>("bar"), document.GetField<int>("bar"));
Assert.AreEqual(documents[i].GetField<string>("baz"), document.GetField<string>("baz"));
}
}
}
}