public async Task <QueryResult <ThirdPartySystemTokenRecord> > QueryByUserKeyPage(string userKey, int page, int pageSize)
        {
            var storeInfo = await GetDBAllStoreInfo(userKey, _thirdPartySystemTokenRecordHashGroupName);

            QueryResult <ThirdPartySystemTokenRecord> result = new QueryResult <ThirdPartySystemTokenRecord>();

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, storeInfo[0], async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }
                await using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                })
                {
                    SqlParameter parameter;

                    command.CommandText = string.Format(@"SET @currentpage = @page;
                                                    SELECT @count = COUNT(*)
                                                    FROM [dbo].[{1}]
                                                    WHERE [userkey]=@userkey                                                         
                                                    

                                                    SELECT {0}
                                                    FROM [dbo].[{1}]
                                                    WHERE [userkey]=@userkey 
                                                    ORDER BY sequence OFFSET (@pagesize * (@currentpage - 1)) ROWS FETCH NEXT @pagesize ROWS ONLY;", StoreHelper.GetThirdPartySystemTokenRecordStoreSelectFields(string.Empty), storeInfo[1]);
                    parameter           = new SqlParameter("@userkey", SqlDbType.NVarChar, 150)
                    {
                        Value = userKey
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@currentpage", SqlDbType.Int)
                    {
                        Value = page
                    };
                    command.Parameters.Add(parameter);


                    parameter = new SqlParameter("@pagesize", SqlDbType.Int)
                    {
                        Value = pageSize
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@count", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    command.Parameters.Add(parameter);


                    await command.PrepareAsync();

                    SqlDataReader reader = null;


                    await using (reader = await command.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var record = new ThirdPartySystemTokenRecord();
                            StoreHelper.SetThirdPartySystemTokenRecordSelectFields(record, reader, string.Empty);
                            record.SystemLoginEndpoint   = await _systemLoginEndpointStore.QueryById(record.SystemLoginEndpointID);
                            record.AuthorizationEndpoint = await _authorizationEndpointStore.QueryById(record.AuthorizationEndpointID);
                            result.Results.Add(record);
                        }
                        await reader.CloseAsync();

                        result.TotalCount  = (int)command.Parameters["@count"].Value;
                        result.CurrentPage = page;
                    }
                }
            });

            return(result);
        }
        public async Task <ThirdPartySystemTokenRecord> QueryByUserKey(string userKey, Guid loginEndpointId, Guid authEndpointId)
        {
            var storeInfo = await GetDBAllStoreInfo(userKey, _thirdPartySystemTokenRecordHashGroupName);

            ThirdPartySystemTokenRecord result = null;
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, storeInfo[0], async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }
                await using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                })
                {
                    SqlParameter parameter;

                    command.CommandText = string.Format(@"SELECT {0} FROM [dbo].[{1}] WHERE userkey=@userkey and systemloginendpointid=@systemloginendpointid and authorizationendpointid=@authorizationendpointid;", StoreHelper.GetThirdPartySystemTokenRecordStoreSelectFields(string.Empty), storeInfo[1]);
                    parameter           = new SqlParameter("@userkey", SqlDbType.NVarChar, 150)
                    {
                        Value = userKey
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@systemloginendpointid", SqlDbType.UniqueIdentifier)
                    {
                        Value = loginEndpointId
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@authorizationendpointid", SqlDbType.UniqueIdentifier)
                    {
                        Value = authEndpointId
                    };
                    command.Parameters.Add(parameter);

                    await command.PrepareAsync();

                    SqlDataReader reader = null;


                    await using (reader = await command.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            result = new ThirdPartySystemTokenRecord();
                            StoreHelper.SetThirdPartySystemTokenRecordSelectFields(result, reader, string.Empty);
                            result.SystemLoginEndpoint   = await _systemLoginEndpointStore.QueryById(result.SystemLoginEndpointID);
                            result.AuthorizationEndpoint = await _authorizationEndpointStore.QueryById(result.AuthorizationEndpointID);

                            if (result.AuthorizationEndpoint == null || result.SystemLoginEndpoint == null)
                            {
                                result = null;
                            }
                        }
                        await reader.CloseAsync();
                    }
                }
            });

            return(result);
        }