2017-09-01 14 views
0

私はKentico 10にカスタムテーブルを持っています。レコードの一部には、緯度と経度がありません。私はこれらの行を除外しようとしていますが、既存の郊外、州、郵便番号の検索を維持しています。現在のAnd/Orの組み合わせは機能していません。提案されたより良い方法はありますか?Kenticoカスタムテーブルクエリまたは組み合わせ

var locationsQuery = CustomTableItemProvider.GetItems("customtable.ProjectName_PostcodeSuburb") 
              .WhereNotNull("Latitude") 
              .And() 
              .WhereNotNull("Longitude") 
              .And() 
              .WhereLike("Suburb", locationLike) 
              .Or() 
              .WhereLike("Postcode", locationLike) 
              .Or() 
              .WhereLike("State", locationLike) 
              .Or() 
              .WhereLike("Suburb + ', ' + State + ', ' + Postcode", locationLike) 
              .Columns("Suburb, State, Postcode") 
              .OrderBy("Suburb, State, Postcode") 
              .TopN(20); 

SQLインジェクションについては心配ですが、SQLパラメータとして渡す方法がわからないパラメータとして渡してみました。

string whereSql = string.Format("Latitude IS NOT NULL AND Longitude IS NOT NULL AND (Suburb LIKE '{0}' OR Postcode LIKE '{0}' OR State LIKE '{0}')", locationLike); 
var locationsQuery = CustomTableItemProvider.GetItems("customtable.ClearView_PostcodeSuburb", whereSql, "Suburb, State, Postcode", 20, "Suburb, State, Postcode"); 

答えて

2

解決方法は見つかりませんでした。 WhereConditionを作成し、それをクエリのどこに渡す必要があります。 https://docs.kentico.com/k10/custom-development/retrieving-database-data-using-objectquery-api

リファレンススナップショットを同じページから -

var localityWhereCondition = new WhereCondition().WhereLike("Suburb", locationLike) 
       .Or() 
       .WhereLike("Postcode", locationLike) 
       .Or() 
       .WhereLike("State", locationLike) 
       .Or() 
       .WhereLike("Suburb + ', ' + State + ', ' + Postcode", locationLike); 

var locationsQuery = CustomTableItemProvider.GetItems("customtable.ProjectName_PostcodeSuburb") 
       .WhereNotNull("Latitude") 
       .And() 
       .WhereNotNull("Longitude") 
       .And() 
       .Where(localityWhereCondition) 
       .Columns("Suburb, State, Postcode") 
       .OrderBy("Suburb, State, Postcode") 
       .TopN(20); 
+0

こんにちは。ドキュメントに関するフィードバックを[feedback link](https://docs.kentico.com/k10/custom-development/retrieving-database-data-using-objectquery-api#feedback-link)を通じて提出するようお願いしますか?リンクはすべてのドキュメントページの一番下にあります。検索中にどのキーワードを使用したか、最終的に解決策を見つけたページ、および/または自分自身を把握しなければならなかった部分を教えてください。ありがとう、本当にありがとう。 – rocky

0

はそれをここにアクセスする方法の全体の要点を得ることができます。

WhereEquals("ColumnName", value) - checks the equality of the value in the specified column with the value specified in the second parameter. 
WhereGreaterThan("ColumnName", value) - compares the value in the specified column with the second parameter. 
WhereNull("ColumnName") - select only rows where the specified column has a NULL value. 
WhereNot(whereCondition) - negates the specified where condition. 
WhereStartsWith("ColumnName", "Value") - only works for text columns. Selects only rows whose value in the specified column starts with the given value.