示例#1
0
        static void TestNano()
        {
            // var db = new DbAccessorNano(_connectionString);
            var                  db    = new DbAccessorNano(_connectionString, (cs) => new MySql.Data.MySqlClient.MySqlConnection(cs));
            DataTable            table = db.Query("select * from Persons");
            IEnumerable <string> names = table.GetColumnValues("Name");

            Console.WriteLine("=== All fields in Name Column ===");
            Console.WriteLine(String.Join(", ", names));

            IEnumerable <Row> rows = table.GetRows(new string[] { "Id", "Name", "Age" });

            Console.WriteLine("=== Some Fields of all Rows ===");
            foreach (var row in rows)
            {
                var idField   = row["Id"];
                var nameField = row["Name"];
                var ageField  = row["Age"];
                Console.WriteLine(String.Join(", ", new string[] { idField, nameField, ageField }));
            }
        }
        public IEnumerable <TEntity> Query <TEntity>(string query) where TEntity : new()
        {
            var table = _db.Query(query);

            return(table.ToEntities <TEntity>());
        }