标签:
using Dapper; using Dapper.Contrib.Extensions; using System.Data.SqlClient; using System.Configuration; namespace Orm { public class RecordBase<T> where T : class { public static SqlConnection OpenConnection() { var ConnStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection connection = new SqlConnection(ConnStr); connection.Open(); return connection; } public static T Get(string id) { using (var conn = OpenConnection()) { return conn.Get<T>(id); } } public bool Update() { using (var conn = OpenConnection()) { //Beblow compile error, because conn.Update<T> expect parameter to be T, i.e. the sub-class, but "this" is parent class. return conn.Update<T>(this); } } } }
标签:
原文地址:http://www.cnblogs.com/wuvist/p/4297547.html