基於Dapper的ORM開源框架

[FasterTable(TableName = "tb_user")] //自動映射表的別名
    public class User
    {
        [FasterKey] //設爲主鍵
        public int UserId { get; set; }
        [FasterColumn(ColumnName ="user_name")] //設置列的別名
        [FasterKey] //多個主鍵
        public string UserName { get; set; }

        public string Password { get; set; }

        public string Email { get; set; }

        public string Phone { get; set; }
    }

   using (var connection = new SqlConnection(connectionStr))
            {
                //新增
                for (int i = 0; i < 10000; i++)
                {
                    connection.Add<User>(new User
                    {
                        UserName = "張強" + i,
                        Password = "123456",
                        Email = "[email protected]",
                        Phone = "18516328675"
                    });
                }

                //查詢
                var list = connection.GetList<User>();
				//多主鍵查詢
                var user = connection.Get<User>(1, "張強0");

                //修改
                var updateRow = connection.Update<User>(new User
                {
                    UserId = 1,
                    UserName = "張強0",
                    Password = "zq",
                    Email = "[email protected]",
                    Phone = "zq"
                });

                //多主鍵刪除

                var deleteRow = connection.Remove<User>(2, "張強1");
            }

源碼:https://github.com/JohnnyZhang0628/Faster

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章