DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TableQueryTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 
4 using Deveel.Data.Mapping;
5 using Deveel.Data.Sql;
6 using Deveel.Data.Types;
7 
8 using NUnit.Framework;
9 
10 namespace Deveel.Data.Linq {
11  [TestFixture]
12  public class TableQueryTests {
13  private ITable table;
14 
15  [SetUp]
16  public void TestSetup() {
17  var tableInfo = new TableInfo(ObjectName.Parse("APP.people"));
18  tableInfo.AddColumn("id", PrimitiveTypes.Bit());
19  tableInfo.AddColumn("first_name", PrimitiveTypes.String(), true);
20  tableInfo.AddColumn("last_name", PrimitiveTypes.String());
21  tableInfo.AddColumn("age", PrimitiveTypes.TinyInt());
22  table = new TemporaryTable(tableInfo);
23 
24  var tempTable = (TemporaryTable) table;
25  tempTable.NewRow(new[] {
26  DataObject.BigInt(1),
27  DataObject.String("Antonello"),
28  DataObject.String("Provenzano"),
30  });
31  tempTable.NewRow(new[] {
32  DataObject.BigInt(2),
33  DataObject.String("Moritz"),
34  DataObject.String("Krull"),
36  });
37 
38  tempTable.BuildIndexes();
39  }
40 
41  [Test]
42  public void ProjectFirst() {
43  IQueryable<Person> queryable = null;
44  Assert.DoesNotThrow(() => queryable = table.AsQueryable<Person>());
45  Assert.IsNotNull(queryable);
46 
47  Person first = null;
48  Assert.DoesNotThrow(() => first = queryable.First());
49  Assert.IsNotNull(first);
50  Assert.AreEqual("Antonello", first.FirstName);
51  Assert.AreEqual("Provenzano", first.LastName);
52  Assert.AreEqual(1, first.Id);
53  Assert.AreEqual(0, first.Age);
54  }
55 
56  class Person {
57  [Column("id")]
58  public int Id;
59 
60  [Column("first_name")]
61  public string FirstName { get; set; }
62 
63  [Column("last_name")]
64  public string LastName { get; set; }
65 
66  [Column("age")]
67  public int Age { get; set; }
68  }
69  }
70 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
The single COLUMN of a table in a database, handling the form of data that can be stored in a cell...
static DataObject Null(SqlType type)
Definition: DataObject.cs:630
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static DataObject String(string s)
Definition: DataObject.cs:592
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
static DataObject TinyInt(byte value)
Definition: DataObject.cs:568
static NumericType TinyInt(int size)
static DataObject BigInt(long value)
Definition: DataObject.cs:580