/// <summary> /// 获取一条数据 /// </summary> /// <param name="user_id">用户id</param> /// <returns></returns> public SystemModel Get(string user_id) { string sql = "select * from t_user where user_id=@user_id"; using (var conn = new Npgsql.NpgsqlConnection(ConnectionString)) { return(conn.QueryFirstOrDefault <SystemModel>(sql, new { user_id = user_id })); } }
protected T QueryFirstOrDefault <T>(string sql, object parameters = null) { using (IDbConnection connection = new Npgsql.NpgsqlConnection(this.connectionString)) { try { connection.Open(); return(connection.QueryFirstOrDefault <T>(sql, parameters)); } catch (Exception exc) { Console.WriteLine(exc); throw exc; } } }