2017-12-31 26 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 개의 다른 푸른 테이블 열을 검색, 내가 어떻게 알 수 십 열의있는 그 결과가 나온거야?

이 클래스는 교회를 정의

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

좀 더 까다 롭습니다. 쿼리가 여러 결과 (행) 또는 단일 결과를 반환 할 것으로 예상됩니까? – Nkosi

+0

@ Nkosi는 단지 하나를 반환하는 의미입니다 –

+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; 
} 

일치 된 당신의 재산/열 이름을 줄 수 있어야

필터에 사용 된 속성 검색 범위를 좁히는 데 사용됩니다.