コード例 #1
0
        public async Task VerifyHasTableWorks()
        {
            DropTable.For <Player>().TryExecute(Connection);

            await Table.Ensure <Player>(Connection);

            await InsertInto.Row(Create("Willem")).ExecuteAsync(Connection);

            await InsertInto.Row(Create("Willemse")).ExecuteAsync(Connection);

            await InsertInto.Row(Create("Bastiaan")).ExecuteAsync(Connection);

            await InsertInto.Row(Create("Harry")).ExecuteAsync(Connection);

            Console.WriteLine(Select <Player> .All().WhereContains(x => x.Name, "illem").Format(SqlFormat.MySql));
            var result = Select <Player> .All().WhereContains(x => x.Name, "illem").ExecuteRead(Connection).ToList();

            Assert.That(result, Has.Count.EqualTo(2));

            result = Select <Player> .All().WhereStartsWith(x => x.Name, "bas").ExecuteRead(Connection).ToList();

            Assert.That(result, Has.Count.EqualTo(1));
            Assert.That(result[0].Name, Is.EqualTo("Bastiaan"));

            result = Select <Player> .All().WhereEndsWith(x => x.Name, "ry").ExecuteRead(Connection).ToList();

            Assert.That(result, Has.Count.EqualTo(1));
            Assert.That(result[0].Name, Is.EqualTo("Harry"));
        }
コード例 #2
0
 public void SelectAll()
 {
     Assert.That(Select <SimpleTableWithName> .All().Format(SqlFormat.MySql),
                 Is.EqualTo("SELECT Name FROM Simple"));
     Assert.That(Select <ExtendedTable> .All().Format(SqlFormat.MySql),
                 Is.EqualTo("SELECT Identifier, Name, Age, Payload FROM Extended"));
 }
コード例 #3
0
        public void SelectAllWithWhere()
        {
            Assert.That(Select <ExtendedTable> .All().WhereEqual(x => x.Name, "Peter").Format(SqlFormat.MySql),
                        Is.EqualTo("SELECT Identifier, Name, Age, Payload FROM Extended\r\nWHERE Name = 'Peter'"));

            Assert.That(Select <ExtendedTable> .All().WhereNotEqual(x => x.Name, "Peter").Format(SqlFormat.MySql),
                        Is.EqualTo("SELECT Identifier, Name, Age, Payload FROM Extended\r\nWHERE Name <> 'Peter'"));

            Guid   identity = Guid.NewGuid();
            string result   =
                string.Format("SELECT Identifier, Name, Age, Payload FROM Extended\r\nWHERE Identifier = '{0}'",
                              identity.ToString("N"));

            Assert.That(Select <ExtendedTable> .All().WhereEqual(x => x.Identifier, identity).Format(SqlFormat.MySql),
                        Is.EqualTo(result));
        }
コード例 #4
0
        public async Task <StudentifyAccount> SelectByUsername(string username)
        {
            var accounts = await Select.All();

            return(accounts.FirstOrDefault(a => a.User.UserName == username));
        }