本文整理汇总了C#中ODatabase.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ODatabase.Select方法的具体用法?C# ODatabase.Select怎么用?C# ODatabase.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODatabase
的用法示例。
在下文中一共展示了ODatabase.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ShouldUpdateClassFromDocument
public void ShouldUpdateClassFromDocument()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
document
.SetField("foo", "foo string value")
.SetField("bar", 12345);
database
.Insert(document)
.Run();
database
.Insert(document)
.Run();
document
.SetField("bar", 54321)
.SetField("baz", "new baz value");
int documentsUpdated = database
.Update(document)
.Run();
Assert.AreEqual(documentsUpdated, 2);
List<ODocument> documents = database
.Select()
.From("TestClass")
.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"));
}
}
}
}
示例3: ShouldSelectUntyped
public void ShouldSelectUntyped()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
string className = "TestVertexClass";
ODocument document1 = new ODocument();
document1
.SetField("foo", "foo string value1")
.SetField("bar", 12345);
ODocument document2 = new ODocument();
document2
.SetField("foo", "foo string value2")
.SetField("bar", 54321);
// create test class
database
.Create.Class("TestVertexClass")
.Extends("OGraphVertex")
.Run();
// load database with some testing data
database
.Create.Vertex(className)
.Set(document1)
.Run();
database
.Create.Vertex(className)
.Set(document2)
.Run();
// perform simple select
List<ORecord> result = database
.Select("foo", "bar")
.From("TestVertexClass")
.ToList();
Assert.AreEqual(result.Count, 2);
Assert.AreEqual(result[0].GetField<string>("foo"), document1.GetField<string>("foo"));
Assert.AreEqual(result[0].GetField<int>("bar"), document1.GetField<int>("bar"));
Assert.AreEqual(result[1].GetField<string>("foo"), document2.GetField<string>("foo"));
Assert.AreEqual(result[1].GetField<int>("bar"), document2.GetField<int>("bar"));
}
}
}
示例4: ShouldSelectFromDocumentOClassNameQuery
public void ShouldSelectFromDocumentOClassNameQuery()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document1 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value1")
.Set("bar", 12345)
.Run();
ODocument document2 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value2")
.Set("bar", 54321)
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
List<ODocument> documents = database
.Select()
.From(document)
.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.IsTrue(documents[i].HasField("foo"));
Assert.IsTrue(documents[i].HasField("bar"));
}
}
}
}
示例5: ShouldSelectFromDocumentOrid
public void ShouldSelectFromDocumentOrid()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document1 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value1")
.Set("bar", 12345)
.Run();
ODocument document2 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value2")
.Set("bar", 54321)
.Run();
List<ODocument> documents = database
.Select()
.From(document2)
.ToList();
Assert.AreEqual(documents.Count, 1);
for (int i = 0; i < documents.Count; i++)
{
Assert.AreEqual(documents[i].ORID, document2.ORID);
Assert.AreEqual(documents[i].OClassName, document2.OClassName);
Assert.AreEqual(documents[i].GetField<string>("foo"), document2.GetField<string>("foo"));
Assert.AreEqual(documents[i].GetField<int>("bar"), document2.GetField<int>("bar"));
}
}
}
}
示例6: 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);
}
}
示例7: ShouldCreateVerticesWithEdge
public void ShouldCreateVerticesWithEdge()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
OVertex vertex1 = database
.Create.Vertex<OVertex>()
.Set("Foo", "foo string value1")
.Set("Bar", 12345)
.Run<OVertex>();
Assert.True(!string.IsNullOrEmpty(vertex1.ORID.ToString()));
Assert.Equal("V", vertex1.OClassName);
Assert.Equal("foo string value1", vertex1.GetField<string>("Foo"));
Assert.Equal(12345, vertex1.GetField<int>("Bar"));
OVertex vertex2 = database
.Create.Vertex<OVertex>()
.Set("Foo", "foo string value2")
.Set("Bar", 54321)
.Run<OVertex>();
Assert.True(!string.IsNullOrEmpty(vertex2.ORID.ToString()));
Assert.Equal("V", vertex2.OClassName);
Assert.Equal("foo string value2", vertex2.GetField<string>("Foo"));
Assert.Equal(54321, vertex2.GetField<int>("Bar"));
OVertex vertex3 = database
.Create.Vertex<OVertex>()
.Set("Foo", "foo string value3")
.Set("Bar", 347899)
.Run<OVertex>();
Assert.True(!string.IsNullOrEmpty(vertex3.ORID.ToString()));
Assert.Equal("V", vertex3.OClassName);
Assert.Equal("foo string value3", vertex3.GetField<string>("Foo"));
Assert.Equal(347899, vertex3.GetField<int>("Bar"));
OEdge edge1 = database
.Create.Edge<OEdge>()
.From(vertex1)
.To(vertex2)
.Set("Foo", "foo string value3")
.Set("Bar", 123)
.Run<OEdge>();
Assert.True(!string.IsNullOrEmpty(edge1.ORID.ToString()));
Assert.Equal("E", edge1.Label);
Assert.Equal("E", edge1.OClassName);
Assert.Equal(vertex2.ORID, edge1.InV);
Assert.Equal(vertex1.ORID, edge1.OutV);
Assert.Equal("foo string value3", edge1.GetField<string>("Foo"));
Assert.Equal(123, edge1.GetField<int>("Bar"));
OEdge edge2 = database
.Create.Edge<OEdge>()
.From(vertex1)
.To(vertex3)
.Set("Foo", "foo string value4")
.Set("Bar", 245)
.Run<OEdge>();
Assert.True(!string.IsNullOrEmpty(edge2.ORID.ToString()));
Assert.Equal("E", edge2.Label);
Assert.Equal("E", edge2.OClassName);
Assert.Equal(vertex3.ORID, edge2.InV);
Assert.Equal(vertex1.ORID, edge2.OutV);
Assert.Equal("foo string value4", edge2.GetField<string>("Foo"));
Assert.Equal(245, edge2.GetField<int>("Bar"));
OVertex loadedVertex1 = database
.Select()
.From(vertex1)
.ToList<OVertex>().First();
Assert.True(!string.IsNullOrEmpty(loadedVertex1.ORID.ToString()));
Assert.Equal("V", loadedVertex1.OClassName);
Assert.Equal(0, loadedVertex1.InE.Count);
Assert.Equal(2, loadedVertex1.OutE.Count);
Assert.True(loadedVertex1.OutE.Contains(edge1.ORID));
Assert.True(loadedVertex1.OutE.Contains(edge2.ORID));
Assert.Equal(vertex1.GetField<string>("Foo"), loadedVertex1.GetField<string>("Foo"));
Assert.Equal(vertex1.GetField<int>("Bar"), loadedVertex1.GetField<int>("Bar"));
OVertex loadedVertex2 = database
.Select()
.From(vertex2)
.ToList<OVertex>().First();
Assert.True(!string.IsNullOrEmpty(loadedVertex2.ORID.ToString()));
Assert.Equal("V", loadedVertex2.OClassName);
Assert.Equal(0, loadedVertex2.OutE.Count);
Assert.Equal(1, loadedVertex2.InE.Count);
Assert.True(loadedVertex2.InE.Contains(edge1.ORID));
Assert.Equal(vertex2.GetField<string>("Foo"), loadedVertex2.GetField<string>("Foo"));
Assert.Equal(vertex2.GetField<int>("Bar"), loadedVertex2.GetField<int>("Bar"));
}
}
}
示例8: Query
static List<ODocument> Query()
{
List<ODocument> documents;
try
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
documents = database
.Select()
.From("TestClass")
.ToList();
using (ODatabase database1 = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
List<ODocument> documents2 = database1
.Select()
.From("TestClass")
.ToList();
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.Message);
documents = new List<ODocument>();
}
return documents;
}
示例9: ShouldGenerateSelectWhereStrings
public void ShouldGenerateSelectWhereStrings()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
string sqlWhereEquals = database
.Select()
.From<TestVertexClass>()
.Where("Foo").Equals(123)
.ToString();
Assert.AreEqual(sqlWhereEquals, "SELECT FROM TestVertexClass WHERE Foo = 123");
string sqlWhereNotEquals = database
.Select()
.From<TestVertexClass>()
.Where("Foo").NotEquals("whoa")
.ToString();
Assert.AreEqual(sqlWhereNotEquals, "SELECT FROM TestVertexClass WHERE Foo != 'whoa'");
string sqlWhereLesserGreater = database
.Select()
.From<TestVertexClass>()
.Where("Foo").Lesser(1)
.And("Bar").LesserEqual(2)
.Or("Baz").Greater(3)
.Or("Gar").GreaterEqual(4)
.ToString();
Assert.AreEqual(sqlWhereLesserGreater, "SELECT FROM TestVertexClass WHERE Foo < 1 AND Bar <= 2 OR Baz > 3 OR Gar >= 4");
string sqlWhereLike = database
.Select()
.From<TestVertexClass>()
.Where("Foo").Like("whoa%")
.ToString();
Assert.AreEqual(sqlWhereLike, "SELECT FROM TestVertexClass WHERE Foo LIKE 'whoa%'");
string sqlWhereIsNull = database
.Select()
.From<TestVertexClass>()
.Where("Foo").IsNull()
.ToString();
Assert.AreEqual(sqlWhereIsNull, "SELECT FROM TestVertexClass WHERE Foo IS NULL");
string sqlWhereContains1 = database
.Select()
.From<TestVertexClass>()
.Where("Foo").Contains("Luke")
.ToString();
Assert.AreEqual(sqlWhereContains1, "SELECT FROM TestVertexClass WHERE Foo CONTAINS 'Luke'");
string sqlWhereContains2 = database
.Select()
.From<TestVertexClass>()
.Where("Foo").Contains("name", "Luke")
.ToString();
Assert.AreEqual(sqlWhereContains2, "SELECT FROM TestVertexClass WHERE Foo CONTAINS (name = 'Luke')");
}
}
}
示例10: ShouldUpdateRemoveFieldQuery
public void ShouldUpdateRemoveFieldQuery()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document1 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value1")
.Set("bar", 11111)
.Run();
ODocument document2 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value2")
.Set("bar", 12345)
.Run();
int documentsUpdated = database
.Update(document2)
.Remove("bar")
.Run();
Assert.AreEqual(documentsUpdated, 1);
List<ODocument> documents = database
.Select()
.From("TestClass")
.Where("foo").Equals("foo string value2")
.ToList();
Assert.AreEqual(documents.Count, 1);
Assert.AreEqual(documents[0].ORID, document2.ORID);
Assert.AreEqual(documents[0].OClassName, document2.OClassName);
Assert.AreEqual(documents[0].GetField<string>("foo"), document2.GetField<string>("foo"));
Assert.IsFalse(documents[0].HasField("bar"));
}
}
}
示例11: ShouldUpdateClassFromObject
public void ShouldUpdateClassFromObject()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class<TestProfileClass>()
.Run();
TestProfileClass profile = new TestProfileClass();
profile.Name = "Johny";
database
.Insert(profile)
.Run();
database
.Insert(profile)
.Run();
profile.Name = "Julia";
profile.Surname = "Bravo";
int documentsUpdated = database
.Update(profile)
.Run();
Assert.AreEqual(documentsUpdated, 2);
List<TestProfileClass> documents = database
.Select()
.From<TestProfileClass>()
.ToList<TestProfileClass>();
Assert.AreEqual(documents.Count, 2);
for (int i = 0; i < documents.Count; i++)
{
Assert.IsTrue(documents[i].ORID != null);
Assert.AreEqual(documents[i].OClassName, typeof(TestProfileClass).Name);
Assert.AreEqual(documents[i].Name, profile.Name);
Assert.AreEqual(documents[i].Surname, profile.Surname);
}
}
}
}
示例12: ShouldSelectFromORID
public void ShouldSelectFromORID()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
TestVertexClass obj = new TestVertexClass();
obj.Foo = "foo string value1";
obj.Bar = 12345;
// create test class
database
.Create.Class<TestVertexClass>()
.Extends("OGraphVertex")
.Run();
// load database with some testing data
ORecord vertex = database
.Create.Vertex<TestVertexClass>()
.Set(obj)
.Run();
// perform simple select
List<TestVertexClass> result = database
.Select()
.From(vertex.ORID)
.ToList<TestVertexClass>();
Assert.AreEqual(result.Count, 1);
Assert.AreEqual(result[0].Foo, obj.Foo);
Assert.AreEqual(result[0].Bar, obj.Bar);
}
}
}
示例13: ShouldUpdateRemoveCollectionItem
public void ShouldUpdateRemoveCollectionItem()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document1 = database
.Insert()
.Into("TestClass")
.Set("foo", new List<string>() { "foo1", "foo2" })
.Set("bar", 11111)
.Run();
ODocument document2 = database
.Insert()
.Into("TestClass")
.Set("foo", new List<string>() { "foo1", "foo2" })
.Set("bar", 12345)
.Run();
int documentsUpdated = database
.Update(document2)
.Remove("foo", "foo2")
.Run();
Assert.AreEqual(documentsUpdated, 1);
List<ODocument> documents = database
.Select()
.From("TestClass")
.Where("bar").Equals(12345)
.ToList();
Assert.AreEqual(documents.Count, 1);
Assert.AreEqual(documents[0].ORID, document2.ORID);
Assert.AreEqual(documents[0].OClassName, document2.OClassName);
List<string> foos = new List<string>() { "foo1" };
Assert.AreEqual(documents[0].GetField<List<string>>("foo").Count, foos.Count);
Assert.AreEqual(documents[0].GetField<List<string>>("foo")[0], foos[0]);
Assert.AreEqual(documents[0].GetField<int>("bar"), document2.GetField<int>("bar"));
}
}
}
示例14: TestCreateVerticesAndHeavyweightEdge
public void TestCreateVerticesAndHeavyweightEdge()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class<TestVertexClass>()
.Extends<OVertex>()
.Run();
database
.Create.Class<TestEdgeClass>()
.Extends<OEdge>()
.Run();
var testVertex1 = CreateTestVertex(1);
var testVertex2 = CreateTestVertex(2);
var testEdge = new TestEdgeClass();
testEdge.SetField("item", 1);
database.Transaction.Add(testVertex1);
database.Transaction.Add(testVertex2);
database.Transaction.AddEdge(testEdge, testVertex1, testVertex2);
Assert.AreEqual(testVertex1.ORID, testEdge.OutV);
Assert.AreEqual(testVertex2.ORID, testEdge.InV);
database.Transaction.Commit();
var createdVertex1 = database.Select().From("V").Where("bar").Equals(1).ToList<OVertex>().First();
var createdVertex2 = database.Select().From("V").Where("bar").Equals(2).ToList<OVertex>().First();
var createdEdge = database.Select().From("E").Where("item").Equals(1).ToList<OEdge>().First();
Assert.That(createdEdge.OutV, Is.EqualTo(createdVertex1.ORID));
Assert.That(createdEdge.InV, Is.EqualTo(createdVertex2.ORID));
var testEdge2 = new TestEdgeClass();
testEdge2.SetField("item", 2);
database.Transaction.AddEdge(testEdge2, createdVertex2, createdVertex1);
database.Transaction.Commit();
createdVertex1 = database.Select().From("V").Where("bar").Equals(1).ToList<OVertex>().First();
createdVertex2 = database.Select().From("V").Where("bar").Equals(2).ToList<OVertex>().First();
var createdEdge2 = database.Select().From("E").Where("item").Equals(2).ToList<OEdge>().First();
Assert.That(createdEdge2.OutV, Is.EqualTo(createdVertex2.ORID));
Assert.That(createdEdge2.InV, Is.EqualTo(createdVertex1.ORID));
}
}
}
示例15: TestCreateManyVertices
public void TestCreateManyVertices()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestVertexClass")
.Extends<OVertex>()
.Run();
for (int i = 0; i < 1000; i++)
{
OVertex testVertex = new OVertex();
testVertex.OClassName = "TestVertexClass";
testVertex.SetField("foo", "foo string value");
testVertex.SetField("bar", i);
database.Transaction.Add(testVertex);
}
database.Transaction.Commit();
var createdVertices = database.Select().From("V").ToList();
Assert.AreEqual(1000, createdVertices.Count);
for (int i = 0; i < 1000; i++)
{
Assert.AreEqual(i, createdVertices[i].GetField<int>("bar"));
}
}
}
}