2016-09-13 6 views
0

ここは私の質問です。私はユーザーページリストを取得したいと思います。このようなSQLを使用して取得:このようなDapper for MySQLクエリ<T>(文字列sql)SQLにはカスタム変数(@rowNum)があります。特殊文字が含まれています@

SELECT * FROM (SELECT @rowNum:[email protected]+1 AS rowNum,User FROM (SELECT 
@rowNum:=0) r,User where [email protected] ORDER BY User.Name) AS a 
WHERE rowNum>=1 AND rowNum<=10 

.NETコード:

connection.Query<T>(sql, new{Name="name"}, transaction, true,commandTimeout); 

と私はプログラムを実行すると、それが例外をスロー:

message: "Object reference not set to an instance of an object.", 
data: { }, 
innerException: null, 
stackTrace: " at MySql.Data.MySqlClient.MySqlConnection.get_ServerThread() at MySql.Data.MySqlClient.MySqlConnection.Abort() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) at Dapper.SqlMapper.<QueryImpl>d__124`1.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) at Infrastructure.Dapper.MysqlMapperExtension.QueryPaged[T](IDbConnection connection, Object condition, String table, String orderBy, Int32 pageIndex, Int32 pageSize, String columns, Boolean isOr, IDbTransaction transaction, Nullable`1 commandTimeout) in E:\Lofter\Code Source\NetCore\MermaidLoft.Alchemy\MermaidLoft.Alchemy\src\Extensions\Infrastructure.Dapper\MysqlMapperExtension.cs:line 312 at MermaidLoft.Alchemy.BaseDomain.UserDomain.UserQueryService.FindUsersForPage(String userName, Int32 pageIndex, Int32 pageSize) in E:\Lofter\Code Source\NetCore\MermaidLoft.Alchemy\MermaidLoft.Alchemy\src\Domains\MermaidLoft.Alchemy.BaseDomain\UserDomain\UserQueryService.cs:line 30 at MermaidLoft.Alchemy.QuickWeb.Controllers.HomeController.Mysql() in E:\Lofter\Code Source\NetCore\MermaidLoft.Alchemy\MermaidLoft.Alchemy\src\MermaidLoft.Alchemy.QuickWeb\Controllers\HomeController.cs:line 40", 
helpLink: null, 
source: "SapientGuardian.MySql.Data", 
hResult: -2147467261 

この問題を解決する方法はありますか?

+0

はこれを見てください?//bugs.mysql.com/bug.php ID = 57671 – mok

+0

それは良い実行します。connection.QueryList (新しい{ID =のuserId}、ConfigSettings.UserTable)。 SingleOrDefault(); –

答えて

0

あなたがユーザー名を確認したいという場合は、特殊文字やそのようなものではないことを意味しているかどうかを確認する必要があります。>>簡単に文字列内の各文字に対してループを作成してintにキャストすることができます。次にcharをasciiに変換してチェックします。

します。https:
string x="aaaa"; 
foreach(char a in x) 
{ 
    int s=(int)a; 
    //(s>=65&&s<=90) capital 
    //(s>=97&&s<=122) small 
    if((s>=65&&s<=90) || (s>=97&&s<=122)) 
       //do your code 

} 
+0

申し訳ありませんが、私の問題です、今私は再び私の質問を編集します。カスタム変数(@rowNum)を使用する方法を解決したいのは、特殊文字@を含んでいます。 –

関連する問題