示例#1
0
文件: Program.cs 项目: MadAza/DbSql
        private static void ReadExample2()
        {
            DbController dbController = DbControllers.GetController(CONNECTION_STRING_NAME);

            int usersCount = dbController.Query("SELECT COUNT(*) FROM [users]").ReadFirst <int>();

            Console.WriteLine(usersCount);
        }
示例#2
0
文件: Program.cs 项目: MadAza/DbSql
        private static void InsertExample()
        {
            DbController dbController = DbControllers.GetController(CONNECTION_STRING_NAME);

            const string INSERT_QUERY = "INSERT INTO [users] (id, name, age) values (@id, @name, @age)";

            dbController.Query(INSERT_QUERY, new { id = Guid.NewGuid(), name = "Example User1", age = 18 }).Execute();
            dbController.Query(INSERT_QUERY, new { id = Guid.NewGuid(), name = "Example User2", age = 21 }).Execute();
            dbController.Query(INSERT_QUERY, new { id = Guid.NewGuid(), name = "Example User3", age = 34 }).Execute();
        }
示例#3
0
文件: Program.cs 项目: MadAza/DbSql
        private static void ReadExample()
        {
            DbController dbController = DbControllers.GetController(CONNECTION_STRING_NAME);

            var users = dbController.Query("SELECT * FROM [users] WHERE age > @age",
                                           new { age = 18 }).Read(() => new User()).ToList();

            foreach (var user in users)
            {
                Console.WriteLine($"Name: {user.Name}. Age: {user.Age}");
            }
        }