确定列azure查询结果来自

问题描述 投票:-1回答: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();

它搜索十个不同的azure表列以匹配用户输入的文本,如何找出结果来自十列中的哪一列?

这个类定义了教会:

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()
        {
        }
    }
}
azure xamarin xamarin.forms
1个回答
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;
}

前缀用于缩小对过滤器中使用的属性的搜索范围。

© www.soinside.com 2019 - 2024. All rights reserved.