程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Dapper一個輕量級的ORM庫,dapperorm

Dapper一個輕量級的ORM庫,dapperorm

編輯:C#入門知識

Dapper一個輕量級的ORM庫,dapperorm


   相關閱讀

http://stackexchange.github.io/dapper-dot-net/

https://github.com/StackExchange/dapper-dot-net

https://msdn.microsoft.com/zh-cn/magazine/mt703432.aspx

引用

  可以直接通過Nuget下載,需要源碼的話可以通過git去下載,上面已經給出鏈接

  

基本操作

  簡單的定義了一張mssql數據表

  

        private static List<Student> Read()
        {
            using (var connect = new SqlConnection(connectionString))
            {
                connect.Open();
                var query = connect.Query<Student>("SELECT TOP 1000 [Id],[Name],[Grade] FROM [TESTDB].[dbo].[Student];");
                return query.ToList();
            }
        }

        private static void Add()
        {
            using (var connect = new SqlConnection(connectionString))
            {
                connect.Open();
                var result = connect.Execute("INSERT INTO [dbo].[Student]([Id],[Name],[Grade])VALUES(@Id,@Name,@Grade);", new[] {
                    new { Id=2,Name="李四",Grade=1},
                    new { Id=3,Name="王五",Grade=1},
                    new { Id=4,Name="趙六",Grade=1}
                });
                Console.WriteLine("影響行數{0}", result);
            }
        }

        private static void Update()
        {
            using (var connect = new SqlConnection(connectionString))
            {
                connect.Open();
                var result = connect.Execute("UPDATE [dbo].[Student]  SET [Grade] = @Grade WHERE Id=@Id; ", new { Id = 2, Grade = 2 });
                Console.WriteLine("影響行數{0}", result);
            }
        }

        private static void Delete()
        {

            using (var connect = new SqlConnection(connectionString))
            {
                connect.Open();
                var result = connect.Execute("DELETE FROM [dbo].[Student] WHERE Id =@Id; ", new { Id = 1 });
                Console.WriteLine("影響行數{0}", result);
            }
        }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved