2017-12-31 71 views
-1

からです決定します列紺碧のクエリの結果は、私はこのコードを持っている

var keyQuery = await MobileService.GetTable<Churches>() 
               .Where(item => item.CK_One == keyEntry.Text || item.CK_Two == keyEntry.Text || item.CK_Three == keyEntry.Text || item.CK_Four == keyEntry.Text || item.CK_Five == keyEntry.Text || item.CK_Six == keyEntry.Text || item.CK_Seven == keyEntry.Text || item.CK_Eight == keyEntry.Text || item.CK_Nine == keyEntry.Text || item.CK_Ten == keyEntry.Text) 
               .ToEnumerableAsync(); 

それは、ユーザーが入力したテキストに一致するための10個の異なる紺碧の表の列を検索し、どのように私は10列のうち見つけることができます結果はから来た?

このクラスは、教会を定義します。

using System; 
namespace ChurchBuilder 
{ 
    public class Churches 
    { 

     public string Id { get; set; } 
     public string Text { get; set; } 
     public string Church_Name { get; set; } 
     public bool Bulletin_Page { get; set; } 
     public bool Prayer_Page { get; set; } 
     public bool Sermons_Page { get; set; } 
     public bool Events_Page { get; set; } 
     public bool Messaging_Page { get; set; } 
     public bool Alert_Bar { get; set; } 
     public bool Push_Notifications { get; set; } 
     public string Master_Admin_Key { get; set; } 
     public string Admin_Key { get; set; } 
     public string Member_Key { get; set; } 
     public string CK_One { get; set; } 
     public string SA_One { get; set; } 
     public string CK_Two { get; set; } 
     public string SA_Two { get; set; } 
     public string CK_Three { get; set; } 
     public string SA_Three { get; set; } 
     public string CK_Four { get; set; } 
     public string SA_Four { get; set; } 
     public string CK_Five { get; set; } 
     public string SA_Five { get; set; } 
     public string CK_Six { get; set; } 
     public string SA_Six { get; set; } 
     public string CK_Seven { get; set; } 
     public string SA_Seven { get; set; } 
     public string CK_Eight { get; set; } 
     public string SA_Eight { get; set; } 
     public string CK_Nine { get; set; } 
     public string SA_Nine { get; set; } 
     public string CK_Ten { get; set; } 
     public string SA_Ten { get; set; } 
     public string Email { get; set; } 
     public double CostPerMonth { get; set; } 
     public bool RolePageOne { get; set; } 
     public bool RolePageTwo { get; set; } 
     public bool RolePageThree { get; set; } 
     public bool RolePageFour { get; set; } 
     public bool RolePageFive { get; set; } 
     public bool RolePageSix { get; set; } 
     public bool RolePageSeven { get; set; } 
     public bool RolePageEight { get; set; } 
     public bool RolePageNine { get; set; } 
     public bool RolePageTen { get; set; } 
     public int Custom_Roles { get; set; } 
     public string Custom_Name_One { get; set; } 
     public string Custom_Name_Two { get; set; } 
     public string Custom_Name_Three { get; set; } 
     public string Custom_Name_Four { get; set; } 
     public string Custom_Name_Five { get; set; } 
     public string Custom_Name_Six { get; set; } 
     public string Custom_Name_Seven { get; set; } 
     public string Custom_Name_Eight { get; set; } 
     public string Custom_Name_Nine { get; set; } 
     public string Custom_Name_Ten { get; set; } 

     public Churches() 
     { 
     } 
    } 
} 
+0

これは少し難解です。クエリは複数の結果(行)または1つだけを返すと予想されますか? – Nkosi

+0

@Nkosiは、ただ1つを返すことを意味しています –

+0

私の頭の上から私はあなたがキーを一致させるためにリフレクションを使うことができ、それが一致したプロパティ/カラム名を与えることができるはずです。 – Nkosi

答えて

0
あなたはキーと一致するためにリフレクションを使用することができ、それは接頭辞である

var key = keyEntry.Text; 

var prefix = "CK_"; 
var church = keyQuery.FirstOrDefault(); 
if (church != null) { 
    var type = church.GetType(); 
    var columnName = type.GetProperties() 
     .Where(property => 
      property.Name.StartsWith(prefix) && property.GetValue(church) == key 
     ).First().Name; 
} 

マッチしたあなたの財産/列名を与えることができるはずです

フィルタで使用されたプロパティの検索を絞り込むために使用されます。

関連する問題