码迷,mamicode.com
首页 > Windows程序 > 详细

C#范型不会用,求助~

时间:2015-02-22 16:54:32      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

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);
            }
        }
    }
}

 

C#范型不会用,求助~

标签:

原文地址:http://www.cnblogs.com/wuvist/p/4297547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!