ORM框架——Dapper的应用
常见的ORM框架有EF,Dapper,NHibernate
参考: http://shuai7boy.iteye.com/blog/2357339
http://www.cnblogs.com/Sinte-Beuve/p/4231053.html
http://www.cnblogs.com/shuai7boy/p/7269928.html
DEMO:
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Reflection; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { IEnumerable<test> test = Selecttests(); Console.ReadKey(); } private static readonly string sqlconnection = "server=.;database=Inferno;integrated security=true;"; public static SqlConnection OpenConnection() { SqlConnection connection = new SqlConnection(sqlconnection); connection.Open(); return connection; } public static IEnumerable<test> Selecttests() { using(IDbConnection conn=OpenConnection()) { const string query = "select *from test order by name;"; return conn.Query<test>(query, null); } } } public class test { public string name{get;set;} public string age{get;set;} public string gender{get;set;} public string userName{get;set;} public string caoZuo { get; set; } } }
百闻不如一见,百见不如一做,只有做了,才知道问题出现在哪儿,才能去解决问题。